This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tree = CSharpSyntaxTree.ParseText(@" | |
using System; | |
public class MyClass | |
{ | |
public static void Main() | |
{ | |
Console.WriteLine(""Hello World!""); | |
Console.ReadLine(); | |
} | |
}"); | |
//We first have to choose what kind of output we're creating: DLL, .exe etc. | |
var options = new CSharpCompilationOptions(OutputKind.ConsoleApplication); | |
options = options.WithAllowUnsafe(true); //Allow unsafe code; | |
options = options.WithOptimizationLevel(OptimizationLevel.Release); //Set optimization level | |
options = options.WithPlatform(Platform.X64); //Set platform | |
var mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location); | |
var compilation = CSharpCompilation.Create("MyCompilation", | |
syntaxTrees: new[] { tree }, | |
references: new[] { mscorlib }, | |
options: options); //Pass options to compilation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment