简体   繁体   English

解决 Microsoft NuGet 包引用中的版本冲突的正确方法是什么?

[英]What is the Correct Way to Resolve Versioning Conflicts in Microsoft NuGet Package References?

In Visual Studio 2019 16.11.5 (latest) I have the 'Visual Studio extension development' workload installed.在 Visual Studio 2019 16.11.5(最新)中,我安装了“Visual Studio 扩展开发”工作负载。

I can use this to create a C# VSIX Project.我可以用它来创建一个 C# VSIX 项目。 If I do this it builds and runs fine as you'd expect, and has no compiler warnings or errors.如果我这样做,它会像您期望的那样构建和运行良好,并且没有编译器警告或错误。

If I go to Tools/Manage NuGet Packages for solution... I can see I have NuGet package Microsoft.VisualStudio.SDK v16.0.206 installed, but the latest version is v16.10.31321.278.如果我转到工具/管理 NuGet 包寻求解决方案...我可以看到我安装了 NuGet 包 Microsoft.VisualStudio.SDK v16.0.206,但最新版本是 v16.10.31321.278。

If I go to the Updates tab I can select the package and click 'Update' to get the latest version.如果我转到“更新”选项卡,我可以选择软件包并单击“更新”以获取最新版本。

The project still builds and runs after I do this, but I get a compiler warning about version incompatibilities of dependent libraries:执行此操作后,该项目仍会构建并运行,但我收到有关依赖库版本不兼容的编译器警告:

Found conflicts between different versions of "Microsoft.VisualStudio.Validation" that could not be resolved. There was a conflict between "Microsoft.VisualStudio.Validation, Version=16.9.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "Microsoft.VisualStudio.Validation, Version=16.10.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". "Microsoft.VisualStudio.Validation, Version=16.9.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "Microsoft.VisualStudio.Validation, Version=16.10.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.

There are more details about where the incompatibility arose, which appear to say the main package references 16.9.0 and some of the dependent libraries reference 16.10.0.有更多关于不兼容的细节,似乎是说主包引用了 16.9.0,一些依赖库引用了 16.10.0。 If I look in project.assets.json I can see that the build actually uses v16.9.32.如果我查看 project.assets.json,我可以看到构建实际上使用了 v16.9.32。

So the question is: what is the correct course of action to remove this compiler warning and safely use the latest SDK to build my VSIX?所以问题是:删除此编译器警告并安全地使用最新的 SDK 来构建我的 VSIX 的正确做法是什么?

Having read around this I see a few options.阅读本文后,我看到了一些选项。 I can suppress the warning, but I can't see how since it has no code.我可以取消警告,但由于它没有代码,我看不到如何。 I can not upgrade the package.我无法升级包。 Or I can install a specific version of Microsoft.VisualStudio.Validation and use a binding redirect to get rid of the warning, although I don't know what the version should be.或者我可以安装特定版本的 Microsoft.VisualStudio.Validation 并使用绑定重定向来消除警告,尽管我不知道版本应该是什么。 If the assembly uses semver it would seem that 16.10.x would be the right library, not the 16.9.32 the build is using.如果程序集使用 semver,则 16.10.x 似乎是正确的库,而不是构建使用的 16.9.32。

The issue is there are two different versions of Microsoft.VisualStudio.Validation.dll files, and VS(MSBuild) can't confirm which to use.问题是有两个不同版本的Microsoft.VisualStudio.Validation.dll文件,VS(MSBuild) 无法确认使用哪个版本。 One is from installed NuGet Package and the other is from system reference(integrated in VS).一个来自已安装的 NuGet 包,另一个来自系统参考(集成在 VS 中)。 Of course, VS chose to use the primary one.当然,VS 选择使用主要的。

The solution should be installing a single Microsoft.VisualStudio.Validation NuGet package, version 16.10.34 .解决方案应该是安装一个Microsoft.VisualStudio.Validation NuGet 包,版本16.10.34 And yes, it is available on nuget.org .是的,它可以在nuget.orgnuget.org

I think this is not a truly solution, it indeed makes the warning disappear, but in my opinion, the issue should be fixed from NuGet package( Microsoft.VisualStudio.SDK ) side.我认为这不是一个真正的解决方案,它确实使警告消失,但在我看来,该问题应该从 NuGet 包( Microsoft.VisualStudio.SDK )方面解决。 During the installation/updating of Microsoft.VisualStudio.SDK package, the version 16.10.XX of the Microsoft.VisualStudio.Validation package should also be installed automatically.在安装/更新Microsoft.VisualStudio.SDK包的过程中,还应自动安装Microsoft.VisualStudio.Validation包的 16.10.XX 版本。 Maybe this will be fixed in a newly released version of Microsoft.VisualStudio.SDK package, I'm not sure.也许这会在Microsoft.VisualStudio.SDK包的新发布版本中得到修复,我不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解决nuget包引用 - Resolving nuget package references 解决演员的正确方法是什么 - What is the correct way to resolve an actor 检查“可能为空”引用的正确方法是什么? - What is the correct way to check for "possibly null" references? 有没有办法在没有 nuget package 的情况下使用 Microsoft.CodeDom.Providers.DotNetCompilerPlatform? - Is there a way to use Microsoft.CodeDom.Providers.DotNetCompilerPlatform without a nuget package? 什么是Microsoft ASP.NET网页2数据Nuget包? - What is the Microsoft ASP.NET Web Pages 2 Data Nuget Package for? MSBuild.exe 给出有关 Nuget package 冲突的错误,这是什么意思? - MSBuild.exe gives errors about Nuget package conflicts, what does it mean? Ninject提供者:解决依赖关系的正确方法是什么 - Ninject Providers: what is the correct way to resolve dependencies nuget 没有使用 nuget package for Microsoft.Extensions.Logging 中指定的内容解决依赖关系 - nuget not resolving dependency using what specified in nuget package for Microsoft.Extensions.Logging 无法解决 C# Active Directory 控制台应用程序中的 Nuget 包 Microsoft.Graph.Auth 问题 - Unable to resolve Nuget package Microsoft.Graph.Auth issue in C# Active Directory console app 从nuget包解析项目程序集引用? - Resolve project assembly references from nuget packages?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM