NuGet - managing and removing multi version packages in single solution

11,217

Solution 1

You can accomplish this in the Nuget Package Manager for Solution (To find the menu, right-click on the solution or go in Tools->Library Package Manager). The Update tab in this dialog will propose to update for multiple projects where the update is applicable. The same applies with uninstall from the Installed tab.

Or with the solution opened, open the NuGet Console, run "Update-Package" to update all packages for all projects. It can also work to update specific packages/projects :

Update-Package [-Id] <string> [-IgnoreDependencies] [-ProjectName <string>] [-Version <string>] [-Safe] [-Source <string>] [-IncludePrerelease]

It will find the same updates than in the dialog, just make sure the right feed (or "All") is selected in "Package Source:" dropdown.

example:

PM> install-package NUnit -version 2.5.9.10348 -ProjectName ProjectA
Successfully installed 'NUnit 2.5.9.10348'.
Successfully added 'NUnit 2.5.9.10348' to ProjectA.

PM> install-package NUnit -version 2.5.10.11092 -ProjectName ProjectB
Successfully installed 'NUnit 2.5.10.11092'.
Successfully added 'NUnit 2.5.10.11092' to ProjectB.

PM> update-package
Updating 'NUnit' from version '2.5.9.10348' to '2.6.0.12054' in project 'ProjectA'.
Successfully removed 'NUnit 2.5.9.10348' from ProjectA.
Successfully installed 'NUnit 2.6.0.12054'.
Successfully added 'NUnit 2.6.0.12054' to ProjectA.
Successfully uninstalled 'NUnit 2.5.9.10348'.
Updating 'NUnit' from version '2.5.10.11092' to '2.6.0.12054' in project 'ProjectB'.
Successfully removed 'NUnit 2.5.10.11092' from ProjectB.
Successfully added 'NUnit 2.6.0.12054' to ProjectB.
Successfully uninstalled 'NUnit 2.5.10.11092'.

Solution 2

Firstly, only changing the xml files is not enough for NuGet to change the references. In fact, sometimes you get errors when you modify packages.config files by hand. package manager console has the ability to update all packages in the solution; you can simply call "Get-Project -All | Update-Package" command.

And secondly, before calling this command, make sure you have proper package sources available.

Share:
11,217
Myles McDonnell
Author by

Myles McDonnell

https://www.linkedin.com/in/mylesmcdonnell/

Updated on June 05, 2022

Comments

  • Myles McDonnell
    Myles McDonnell almost 2 years

    SCENARIO

    One VS solution with n projects. Project A references package Y v1, Project B references package Y v2. It is now not possible to update all references to package Y for all projects in the solution using the NuGet package manage dialog at the solution level, it is only possible to do this when all projects reference the same version of package Y. Not a big deal for only two projects, but I'm dealing with lots of projects that through poor package management are referencing many package versions when they should all reference the same version.

    Before I spend the afternoon writing a console app. to auto update all package.config files for a solution so that each referenced package is only referenced via it's latest version (latest referenced, not the very latest, with exceptions/caveats etc)....is there a tool/method for doing this already? Or some other approach I am unaware of?

    • Ventsyslav Raikov
      Ventsyslav Raikov about 12 years
      Friday afternoon is great time for this !
    • Ritch Melton
      Ritch Melton about 12 years
      Have you tried using sed or awk?
    • mbx-mbx
      mbx-mbx about 12 years
      I thought I did this today.... right click on solution, manage packages, update? I swear I just did that?
    • Myles McDonnell
      Myles McDonnell about 12 years
      @Magrangs you are right, it works, although I still have to do one package at a time (the command from daryal doesn't work in my case) I was lead to believe it does not so I have a horrible feeling something is going to go awry :S
    • mbx-mbx
      mbx-mbx about 12 years
      I'm glad I didn't imagine it, could have been worrying.
    • Myles McDonnell
      Myles McDonnell about 12 years
      Yep, it all went very very wrong. My solution would not build once I have updated all package ref via the dialog and I had to rollback. I think NuGet gets confused when there are refs to difference versions of the same package with a single solution. I'm going to try 'fixing' all the the package.config files to ref common version then try again.
  • Myles McDonnell
    Myles McDonnell about 12 years
    That console command reported no updates available for all package refs in every proj in the solution but there are updates and I can update then one at a time via the dialog.
  • daryal
    daryal about 12 years
    can you try deleting packages folder in the solution except repositories.config file then running the command again?