.NET Core 的新 .csproj 格式的 Roslyn 工作区 [英] Roslyn workspace for .NET Core's new .csproj format
问题描述
我一直在研究使用 Roslyn 的工作区 API 加载项目的 VS Code 扩展,目前该扩展通过 ProjectJsonWorkspace 支持 .NET Core 的旧
在 project.json
格式Microsoft.DotNet.ProjectModel.Workspaces
包中输入.
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 工作区,这可以通过下面对 关注 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:MyCodeMyProject.csproj");
AdhocWorkspace workspace = analyzer.GetWorkspace();
同一个库还允许您引用解决方案文件.
The same library will also allow you to reference a solution file too.
这篇关于.NET Core 的新 .csproj 格式的 Roslyn 工作区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!