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 C | |
{ | |
public static void Main() | |
{ | |
Console.WriteLine(""Hello World!""); | |
Console.ReadLine(); | |
} | |
}"); | |
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. | |
if(!emitResult.Success) | |
{ | |
foreach(var diagnostic in emitResult.Diagnostics) | |
{ | |
Console.WriteLine(diagnostic.ToString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment