将我的 Visual Studio 扩展从旧的 csproj 移动到 SDK 样式的 csproj 后出现 NuGet 问题

NuGet problems after moving my Visual Studio extension from old csproj to SDK-style csproj

我已经将我的 Visual Studio 扩展从旧的 csproj 格式切换到新的 SDK 样式格式,并希望通过以下包引用获得我需要的一切(以前我不得不引用 100 个不同的包我的 packages.config)

<PackageReference Include="Microsoft.VisualStudio.LanguageServices" Version="3.8.0" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.0.206" />
<PackageReference Include="NuGet.VisualStudio" Version="5.8.0" />

但是,虽然扩展是在 Visual Studio 中构建的,但我 运行 在使用 MSBuild 构建扩展时遇到了问题(恢复 NuGet 包时):

"C:\Path\MyExt\MyExtension.sln" (Build target) (1) ->
   "C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj" (default target) (9) ->
     C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.CoreUtility (>= 16.8.39) but Microsoft.VisualStudio.CoreUtility 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.CoreUtility 16.8.239 was resolved.
     C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.CoreUtility (>= 16.8.39) but Microsoft.VisualStudio.CoreUtility 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.CoreUtility 16.8.239 was resolved.
     C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.Text.Data (>= 16.8.39) but Microsoft.VisualStudio.Text.Data 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.Text.Data 16.8.239 was resolved.
     C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.Text.Data (>= 16.8.39) but Microsoft.VisualStudio.Text.Data 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.Text.Data 16.8.239 was resolved.
     C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.Text.Logic (>= 16.8.39) but Microsoft.VisualStudio.Text.Logic 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.Text.Logic 16.8.239 was resolved.
     C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.Text.Logic (>= 16.8.39) but Microsoft.VisualStudio.Text.Logic 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.Text.Logic 16.8.239 was resolved.

确实,这些包不在 NuGet 上。这是 Microsoft.VisualStudio.SDK 包的问题吗?我做错了什么吗?

我认为问题与 Microsoft.CodeAnalysis.EditorFeatures 包本身有关。你应该联系作者。

只是这个问题被new-sdk工程和你设置的true放大了

实际上,我在 net core 控制台项目中也遇到了同样的问题。

你可以看到这个:

nuget 包有依赖 >=16.8.39.

但是,Microsoft.VisualStudio.CoreUtility没有版本16.8.39但是有16.8.239版本。这是作者设计的。并且根据nuget的机制,它会安装最低版本的依赖,但是new-sdk风格的项目无法自动识别无效版本,出现这个警告。但是 packages.config 的非 sdk 样式项目将自动安装有效版本的 nuget 依赖项。

所以这个问题是nuget包的设计问题和new-sdk风格项目的特殊性的双重影响。在这种情况下它只是被放大了。

============================================

解决方法

要解决此问题,请尝试以下操作:

1)首先,禁用Project Properties下的TreatWarningsAsErrors节点-->Build

2)手动安装

Microsoft.VisualStudio.CoreUtility 16.8.239

Microsoft.VisualStudio.Text.Data 16.8.239

Microsoft.VisualStudio.Text.Logic 16.8.239

另外添加 nuget 包以更新依赖项。

3)然后启用TreatWarningsAsErrors进行检查。