Beispiel #1
0
        public IScript CompileScript(Setting setting)
        {
            IScript result = null;

            if (!string.IsNullOrEmpty(setting.m_script))
            {
                string fileName = AppDomain.CurrentDomain.BaseDirectory + "\\" + setting.m_guid + ".dll";
                try
                {
                    System.IO.File.Delete(fileName);
                }
                catch { }
                CompileParam    cp = new CompileParam(setting.m_script, fileName, false, new string[] { "System.dll", "FileNotify2.dll" });
                CompilerResults cr = ExecuteCompileScript.Compile(cp);
                if (cr.Errors.Count == 0)
                {
                    result = LoadScript(fileName);
                }
                else
                {
                    Console.WriteLine("Error compiling {0}", setting.m_name);
                    foreach (CompilerError error in cr.Errors)
                    {
                        Console.WriteLine(error);
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        // This version load the compiled assembly in the current domain => you can't unload it
        static public CompilerResults Compile(CompileParam cparam)
        {
            string[] dependencies = new string[] { "System.dll" };
            if (cparam.m_dependencies != null)
            {
                dependencies = cparam.m_dependencies;
            }

            System.IO.Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider();
            CompilerParameters cp = new CompilerParameters();

            cp.GenerateExecutable      = false;
            cp.OutputAssembly          = cparam.m_outName;
            cp.IncludeDebugInformation = cparam.m_bDebug;
            foreach (string s in dependencies)
            {
                cp.ReferencedAssemblies.Add(s);
            }
            cp.GenerateInMemory      = false;
            cp.WarningLevel          = 3;
            cp.TreatWarningsAsErrors = false;
            cp.CompilerOptions       = "/optimize";

            // Invoke compilation.
            CompilerResults cr = provider.CompileAssemblyFromSource(cp, cparam.m_inSource);

            return(cr);
        }