Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
var tree = CSharpSyntaxTree.ParseText(@"
using System;
public class MyClass
public static void Main()
Console.WriteLine(""Hello World!"");
//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