public static byte[] TestRoslyn() { var mainProgramString = @"public class Program { public static void Main() { int i=3; System.Console.Write(""hello world!!!!""); } }"; byte[] result = DotNetCompiler.CompileConsoleApp(mainProgramString); return(result); //File.WriteAllBytes(@"c:\temp\try.exe", mainCompiledResult); }
public static byte[] CompileConsoleApp(string sourceCode) { // create the Roslyn compilation for the main program with // ConsoleApplication compilation options // adding references to A.netmodule and B.netmodule var mainCompilation = DotNetCompiler.CreateCompilationWithMscorlib ( "program", sourceCode, compilerOptions: new CSharpCompilationOptions(OutputKind.ConsoleApplication) ); // emit the compilation result to a byte array // corresponding to A.netmodule byte code byte[] result = DotNetCompiler.EmitToArray(mainCompilation); return(result); }