获取从netFard中的ProjectFile加载的Microsoft.CodeAnalysis.Project的引用

时间:2017-12-17 11:20:22

标签: roslyn .net-standard roslyn-code-analysis

我尝试将一些代码移植到netstandard,以便它可以在Linux上运行。

以前我使用MSBuildWorkspace来获取工作区并加载项目。

MSBuildWorkspace workspace = MSBuildWorkspace.Create();
Microsoft.CodeAnalysis.Project project = await workspace.OpenProjectAsync(projectPath);

当我切换到netstandard时,不再有MSBuildWorkspace。如何从Project文件中获取.csproj实例文件。

修改

包含我引用的所有包的项目文件。

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.5.180" />
    <PackageReference Include="Microsoft.CodeAnalysis" Version="2.6.1" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.6.1" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.6.1" />
    <PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="2.6.1" />
    <PackageReference Include="Microsoft.DotNet.ProjectModel" Version="1.0.0-rc3-1-003177" />
  </ItemGroup>

</Project>

1 个答案:

答案 0 :(得分:1)

MSBuildWorkspace将包含在单独的包中。见issue