The current approach in the C# plugin to create a complete semantic model of the parsed program is that it is expected that the parsed .NET project was built previously and the build folder is an input folder, and adding all found DLLs as reference to the CSharpCompilation object will load required types for parsing. This includes BCL DLLs and types as well.
This could be significantly simplified. Instead of manually collecting files and DLLs, let Roslyn's MSBuildWorkspace open the .csproj or .sln directly — it resolves references automatically via NuGet/SDK. Minimal working example:
using Microsoft.CodeAnalysis.MSBuild;
var workspace = MSBuildWorkspace.Create();
var solution = await workspace.OpenSolutionAsync("MyApp.sln");
foreach (var project in solution.Projects)
{
var compilation = await project.GetCompilationAsync();
foreach (var tree in compilation.SyntaxTrees)
{
var model = compilation.GetSemanticModel(tree);
// execute visitor
}
}
This requires the Microsoft.CodeAnalysis.Workspaces.MSBuild NuGet package, which we already plan to use in #847 anyway.
The current approach in the C# plugin to create a complete semantic model of the parsed program is that it is expected that the parsed .NET project was built previously and the build folder is an input folder, and adding all found DLLs as reference to the
CSharpCompilationobject will load required types for parsing. This includes BCL DLLs and types as well.This could be significantly simplified. Instead of manually collecting files and DLLs, let Roslyn's
MSBuildWorkspaceopen the .csproj or .sln directly — it resolves references automatically via NuGet/SDK. Minimal working example:This requires the
Microsoft.CodeAnalysis.Workspaces.MSBuildNuGet package, which we already plan to use in #847 anyway.