Nuget changes existing shared package references to last package referenced


  • We are using an internal nuget server to handle a handful of common class libraries, and we manage our nuget packages at the solution level.

    When a project (say MyProject) references a common library, say Newtonsoft.Json, the reference proprerly comes from C:\dev\myproject\packages\Newtonsoft.Json.9.0.1\lib\net461\Newtonsoft.Json.dll. The moment I add another package (say CommonProject) to MyProject that also references Newtonsoft.Json, the reference in MyProject CHANGES to C:\dev\myproject\packages\CommonProject\lib\net461\Newtonsoft.Json.dll.

    This causes serious problems and a great deal of dll hell. The moment one of these common projects changes one of their references - let's say CommonProject no longer uses Newtonsoft.Json. The moment MyProject upgrades to the latest version of CommonProject, MyProject will now fail to compile because it can no longer find Newtonsoft.Json in C:\dev\myproject\packages\CommonProject\lib\net461\Newtonsoft.Json.dll. MyProject still lists Newtonsoft.Json as a nuget package reference, and the Newtonsoft dll is still sitting pretty in the Newtonsoft.Json folder of packages, but the dll reference remains jacked up from when I first added the CommonProject nuget package. Nuget stupidly CHANGED every single shared package reference to map directly to the CommonProject folder instead of the packages folders for each of those packages. Even if the projects are referencing the exact same versions of the same packages, nuget still changes the references.

    Moving all shared package references to the folder of the last package added is making me think that nuget isn't managing packages at all.  The pain this is causing is forcing us to move off of nuget completely.  It causes the exact same problem as if someone had referenced a dll directly from some other project's bin folder.  All of our references are incredibly fragile due to this nuget behavior.

    Please tell me we're doing something wrong, and let me know how I can get the packages to be properly referenced from their respective folders.  If two projects use the exact same version of a third-party package, the dll references to those third-party packages should come from those third-party package's folders, not whatever package happened to be the last one added.

    • Edited by thardy Tuesday, April 18, 2017 3:41 PM
    Tuesday, April 18, 2017 3:33 PM

All replies

  • What version of VS are you using? VS2017 in combination with NuGet Package Manager 3.x have resolve some of these issues. You should probably post this question over on GitHub for NuGet as they are responsible for this extension and can probably better explain how to work around it.

    Wednesday, April 19, 2017 2:37 PM
  • We are using VS2015.  We did see that core and VS2017 have some fixes that might be very helpful, but we cannot move to those yet due to legacy code requirements.

    I will post this over on GitHub.  Thanks for pointing that out.

    Thursday, April 20, 2017 2:14 PM