Create a new console application with one line in the Main
method: Console.WriteLine("Hello World")
Remember the path to the .vbproj
file and replace it in the example.
Create a new Console Application and install the Microsoft.CodeAnalysis
NuGet package and try the following code:
Const projectPath = "C:\HelloWorldApplication\HelloWorldProject.vbproj"
' Creating a build workspace.
Dim workspace = MSBuildWorkspace.Create()
' Opening the Hello World project.
Dim project = workspace.OpenProjectAsync(projectPath).Result
' Getting the compilation.
Dim compilation = project.GetCompilationAsync().Result
For Each tree In compilation.SyntaxTrees
Console.WriteLine(tree.FilePath)
Dim rootSyntaxNode = tree.GetRootAsync().Result
For Each node In rootSyntaxNode.DescendantNodes()
Console.WriteLine($" *** {node.Kind()}")
Console.WriteLine($" {node}")
Next
Next
Console.ReadKey()
This will print all the files and all the syntax nodes in your Hello World project.