简体   繁体   中英

VS2017 - Consolidating Newtonsoft.Json.dll (but it could just as easily be any varied version nuget package)

I've a solution with somewhere in the region of 60 projects, most of which use Newtonsoft.Json.dll and many of which reference each other. Things were building nicely, no warnings.

Took a look at the Consolidate feature of the nugget package manager, and it seemed to be quite useful- multiple projects using different versions of Newtonsoft could be quickly regularised to all use the same version. Most projects use the same version, some were ahead by a few minors, some lagged by at most one major version. Click click done, all projects now have the same version installed and referenced. Apparently.

Warnings appear about finding different conflicting versions of the same assembly, so I decided to file-find every Newtonsoft.Json.dll under the project tree and erase them, and also erase the solutiondir\\packages\\Newtonsoft.Json folder, then do a package restore and a rebuild the solution..

Bizarrely, it doesn't seem to have helped.. I genuinely thought that clearing the old versions and having had NPM make every project in the solution on the same version, would mean there weren't 9 different versions of it kicking around, but sure enough doing a search for the dll turns up different sized files all over the solution tree

What's the right way to handle this and kill off the warnings about conflicting assemblies post consolidate?

I was able to resolve the warnings for my context, after realising that many of the projects in the solution had a web config binding redirect that called for 0.0.0.0-6.0.0.0 of Newtonsoft.Json to be redirected to 6.0.0.0

The installed version (5.0.2) had an assembly version of 4.5.0.0, the first one that I could find that had an assemblyversion of 6.0.0.0 Rather than adjust the binding redirects, I used the NPM to upgrade all the Newtonsoft.Json to v6.0.1 and subsequently all the projects references to it became dependent on an assemblyversion for it of 6.0.0.0

I presume thus that when a binding redirect specifies a version of a library that doesn't exist in the solution, and it is successfully fund elsewhere, that other version may become a conflicting version with the locally referenced one.

Edit: It appears that NuGet Package Manager (Console)/Powershell can also regularise the binding redirects, with the following command:

Get-Project –All | Add-BindingRedirect

More info: https://weblog.west-wind.com/posts/2014/Nov/29/Updating-Assembly-Redirects-with-NuGet

TLDR; ensure your binding redirects reference the version of a lib that is available in the project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM