Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet - managing and removing multi version packages in single solution

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?

like image 751
Myles McDonnell Avatar asked Mar 30 '12 11:03

Myles McDonnell


1 Answers

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'.
like image 134
Alexandre Dion Avatar answered Oct 19 '22 10:10

Alexandre Dion