Create workspace from MSBuild project
suggest changeAdd the Microsoft.CodeAnalysis.CSharp.Workspaces NuGet package before continuing.
var workspace = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create();
var project = await workspace.OpenProjectAsync(projectFilePath);
var compilation = await project.GetCompilationAsync();
foreach (var diagnostic in compilation.GetDiagnostics()
.Where(d => d.Severity == Microsoft.CodeAnalysis.DiagnosticSeverity.Error))
{
Console.WriteLine(diagnostic);
}
This loads an existing project, compiles it, and reports errors. The result stays in memory, where both the syntax and the semantic model are available.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents