Skip to content

Instantly share code, notes, and snippets.

Created March 15, 2016 10:35
Show Gist options
  • Select an option

  • Save anonymous/2e07b9c36ac0fbadaf72 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/2e07b9c36ac0fbadaf72 to your computer and use it in GitHub Desktop.
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.VisualBasic
Imports Microsoft.VisualBasic.CompilerServices
Module Module1
Sub Main()
Dim code = "Module Module1" + Environment.NewLine +
"Sub Main()" + Environment.NewLine +
"System.Console.WriteLine(My.Application.Info.AssemblyName)" + Environment.NewLine +
"End Sub" + Environment.NewLine +
"End Module"
Dim tree = VisualBasicSyntaxTree.ParseText(code)
Dim compilation = VisualBasicCompilation.Create("test").
AddSyntaxTrees(tree).
AddReferences(MetadataReference.CreateFromFile(GetType(Object).Assembly.Location)).
AddReferences(MetadataReference.CreateFromFile(GetType(StandardModuleAttribute).Assembly.Location))
Dim emitResult = compilation.Emit("test.exe")
If Not emitResult.Success Then
Console.Write(String.Join(Environment.NewLine, emitResult.Diagnostics))
End If
Console.ReadLine()
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment