using Microsoft.CodeAnalysis.MSBuild; using System.Threading.Tasks; class Program { static async Task Main(string[] args) { using (var workspace = MSBuildWorkspace.Create()) { // ... } } }
var project = await workspace.OpenProjectAsync("SomeProject.csproj");
var syntaxTree = await document.GetSyntaxTreeAsync(); var root = await syntaxTree.GetRootAsync(); var methods = root.DescendantNodes().OfTypeThis example shows how to retrieve syntax nodes from a document. The `GetSyntaxTreeAsync` method returns the syntax tree of the document, which can then be traversed using the `DescendantNodes` method to find specific syntax nodes. Package Library: Microsoft.CodeAnalysis.CSharp.Workspaces (for C#) or Microsoft.CodeAnalysis.VisualBasic.Workspaces (for VB.NET) In summary, Microsoft.CodeAnalysis Workspace is a powerful library for interacting with code written in C# or VB.NET. It provides APIs for loading code, analyzing syntax, and accessing metadata, making it a valuable tool for building code analysis and generation tools. The package libraries vary based on the specific functionality you need.();