private ProjectCompiler RunCode_CompileCode(CompilerProjectReader projectReader, string assemblyFilename, string sourceFile) { ProjectCompiler compiler = new ProjectCompiler(CompilerManager.Current.Win32ResourceCompiler, CompilerManager.Current.ResourceCompiler); //try //{ compiler.SetOutputAssembly(assemblyFilename + ".dll"); //compiler.AddSource(new CompilerFile(sourceFile)); compiler.AddSource(new CompilerFile { File = sourceFile }); //if (projectReader != null) // compiler.SetProjectCompilerFile(projectReader.GetProjectCompilerFile()); // CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml //compiler.SetParameters(GetRunSourceConfigCompilerDefaultValues(), runCode: true); compiler.SetParameters(projectReader, runCode: true); compiler.SetTarget("library"); CompilerManager.Current.UpdateAssemblies(compiler.Assemblies.Values); compiler.Compile(); return(compiler); }
public void GenerateCSharpCode(string code) { string file = zpath.PathSetExtension(_assemblyFilename, ".cs"); using (StreamWriter sw = zFile.CreateText(file)) { CSharpCodeWriter generateCode = new CSharpCodeWriter(sw); // using generateCode.WriteUsings(_usings.Keys); // open namespace generateCode.OpenNameSpace(_nameSpace); // open class // public static partial class ... generateCode.OpenClass(_className, ClassOptions.Public | ClassOptions.Static | ClassOptions.Partial); // open function // public static void Run() generateCode.WriteLine("public static void {0}()", _runMethodName); generateCode.WriteLine("{"); generateCode.WriteLine(code); generateCode.WriteLine("}"); // close class generateCode.CloseClass(); // close namespace generateCode.CloseNameSpace(); } _compiler.AddSource(new CompilerFile(file)); }
private ProjectCompiler RunCode_CompileCode(CompilerProjectReader compilerProject, string assemblyFilename, string sourceFile) { ProjectCompiler compiler = new ProjectCompiler(CompilerManager.Current.Win32ResourceCompiler, CompilerManager.Current.ResourceCompiler); //try //{ compiler.SetOutputAssembly(assemblyFilename + ".dll"); compiler.AddSource(new CompilerFile(sourceFile)); if (compilerProject != null) compiler.SetProjectCompilerFile(compilerProject.GetProjectCompilerFile()); // CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml //compiler.SetParameters(GetRunSourceConfigCompilerDefaultValues(), runCode: true); compiler.SetParameters(compilerProject, runCode: true); compiler.SetTarget("library"); CompilerManager.Current.UpdateAssemblies(compiler.Assemblies.Values); compiler.Compile(); return compiler; }