I've been working on a VS Code extension that uses Roslyn's workspace API to load a project, at the moment the extension supports .NET Core's old project.json
format via the ProjectJsonWorkspace
type in the Microsoft.DotNet.ProjectModel.Workspaces
package.
With the new tooling changes being released soon I'm keen to support the new .csproj
build format but can't appear to find a .NET Standard compliant workspace that supports it.
My understanding is that as it's using MSBuild, I will need to use the MSBuild (Microsoft.CodeAnalysis.MSBuild
) package, however it does not support .NET Standard at this moment in time.
What is the best solution if one exists, or will I have to look at creating my own workspace implementation?
Having spoken with various people it appears that there is no .NET Standard compatible MS Build workspace, this can be seen by this answer below to the following GitHub issue:
We haven't done the work to make MSBuildWorkspace work properly with the new MSBuild cross-platform. In the meantime, you might look at what omnisharp does to populate it's workspace.
So it seems that at the time of writing if you want to target the MSBuild workspace in a .NET Standard compliant project then you'll need to build your own custom workspace using Roslyn's workspace API, this is exactly how OmniSharp do it.
Update (16/10/2017):
Whilst MSBuildWorkspace does still not support .NET Standard, there is a library called Buildalyzer that works cross-platform and will generate an AdhocWorkspace for you, allowing you to achieve the same goal.
using Buildalyzer.Workspaces;
// ...
AnalyzerManager manager = new AnalyzerManager();
ProjectAnalyzer analyzer =
manager.GetProject(@"C:\MyCode\MyProject.csproj");
AdhocWorkspace workspace = analyzer.GetWorkspace();
The same library will also allow you to reference a solution file too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With