Home > Back-end >  What is the Correct Way to Resolve Versioning Conflicts in Microsoft NuGet Package References?
What is the Correct Way to Resolve Versioning Conflicts in Microsoft NuGet Package References?

Time:11-12

In Visual Studio 2019 16.11.5 (latest) I have the 'Visual Studio extension development' workload installed.

I can use this to create a C# VSIX Project. 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.

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. If I look in project.assets.json I can see that the build actually uses 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?

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. 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.

CodePudding user response:

The issue is there are two different versions of Microsoft.VisualStudio.Validation.dll files, and VS(MSBuild) can’t confirm which to use. One is from installed NuGet Package and the other is from system reference(integrated in VS). Of course, VS chose to use the primary one.

The solution should be installing a single Microsoft.VisualStudio.Validation NuGet package, version 16.10.34. And yes, it is available on nuget.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. 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. Maybe this will be fixed in a newly released version of Microsoft.VisualStudio.SDK package, I’m not sure.

  • Related