using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
SyntaxTree tree = CSharpSyntaxTree.ParseText(
using System.Collections.Generic;
static void Main(string[] args)
Console.WriteLine(""Hello, TDN!"");
var root = (CompilationUnitSyntax)tree.GetRoot();
var compilation = CSharpCompilation.Create("HelloTDN")
.AddReferences(references: new[] { MetadataReference.CreateFromAssembly(typeof(object).Assembly) })
private static Assembly CompileSourceRoslyn(string fooSource)
using (var ms = new MemoryStream())
string assemblyFileName = "gen" + Guid.NewGuid().ToString().Replace("-", "") + ".dll";
CSharpCompilation compilation = CSharpCompilation.Create(assemblyFileName,
new[] {CSharpSyntaxTree.ParseText(fooSource)},
MetadataReference.CreateFromAssembly(typeof(object).Assembly)
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
Assembly assembly = Assembly.Load(ms.GetBuffer());