我尝试将一些代码移植到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>