.NET Core的新.csproj格式的Roslyn工作区 [英] Roslyn workspace for .NET Core's new .csproj format
问题描述
我一直在研究使用Roslyn的工作区API加载项目的VS Code扩展,目前该扩展支持.NET Core的旧 project.json
格式通过 Microsoft.DotNet.ProjectModel.Workspaces
包中的 ProjectJsonWorkspace
类型。
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.
随着新的工具更改即将发布,我渴望支持新的 .csproj
构建格式,但似乎找不到.NET Standard。
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.
我的理解是,由于它正在使用MSBuild,因此我需要使用MSBuild( Microsoft.CodeAnalysis.MSBuild
)程序包,但目前不支持.NET Standard。
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?
推荐答案
与各种各样的人交谈过,似乎没有与.NET Standard兼容的MS Build Workspac e,可以通过以下遵循GitHub问题的答案得到:
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:
我们尚未完成使MSBuildWorkspace与新的MSBuild跨平台正常工作的工作。同时,您可能会看到omnisharp会如何填充它的工作区。
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.
因此在撰写本文时,如果您想要以.NET Standard兼容项目中的MSBuild工作区为目标,则需要使用Roslyn的工作区API构建自己的自定义工作区,这正是OmniSharp的工作方式。
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.
更新(16/10/2017):
尽管MSBuildWorkspace仍不支持.NET Standard,但有一个名为 Buildalyzer 可以跨平台运行,并会为您生成一个AdhocWorkspace,使您可以实现相同的目标。
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.
这篇关于.NET Core的新.csproj格式的Roslyn工作区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!