Skip to content

Instantly share code, notes, and snippets.

Last active November 24, 2017 16:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
var tree = CSharpSyntaxTree.ParseText(@"
using System;
public class C
public static void Main()
Console.WriteLine(""Hello World!"");
var mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);
var compilation = CSharpCompilation.Create("MyCompilation",
syntaxTrees: new[] { tree }, references: new[] { mscorlib });
//Emitting to file is available through an extension method in the Microsoft.CodeAnalysis namespace
var emitResult = compilation.Emit("output.exe", "output.pdb");
//If our compilation failed, we can discover exactly why.
foreach(var diagnostic in emitResult.Diagnostics)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment