Skip to content

Instantly share code, notes, and snippets.

@svick
Created March 15, 2016 01:43
Show Gist options
  • Select an option

  • Save svick/3258268ac8c34c7e92ac to your computer and use it in GitHub Desktop.

Select an option

Save svick/3258268ac8c34c7e92ac to your computer and use it in GitHub Desktop.
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.VisualBasic
Module Module1
Sub Main()
Dim code = "Module Module1
Sub Main()
Console.WriteLine(My.Application.Info.AssemblyName)
End Sub
End Module"
Dim tree = VisualBasicSyntaxTree.ParseText(code)
Dim compilation = VisualBasicCompilation.Create("test").
AddSyntaxTrees(tree).
AddReferences(MetadataReference.CreateFromFile("C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll")).
AddReferences(MetadataReference.CreateFromFile("C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Microsoft.VisualBasic.dll"))
Dim semantics = compilation.GetSemanticModel(tree)
Dim errors = semantics.GetSyntaxDiagnostics()
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment