NuGet ~ UpdatePackage Commands

Introduction

I often have to import solutions into the main project. Usually, each solution may use different versions of some components or, sometimes, new libraries. I have seen that a common practice is to run the Update-Manager on the whole project when, for example, it would be enough to run it only for the solution concerned.

Here are some of the commands to use in certain situations.

List of (some) parameters

Param Description
-ProjectName Specifies the name of the project in which packages should be updated.
-Safe If set, NuGet will only update to a new version that has the same major and minor versions as the previous package. For example, if the old version is 1.1.0, NuGet will accept the update package with version of 1.1.1 or 1.1.9999 but it will not accept 1.2.0.
-Version Specifies the new target version of the package as a result of the update.
-Reinstall If set, NuGet will uninstall and reinstall the packages to the same version.

Examples

Update a particular package in a project to the latest version:

Update-Package jQuery -ProjectName MyProject

Update a particular package in a project to the latest version, using safe update rule:

Update-Package jQuery -ProjectName MyProject -Safe

Update a particular package in a project to a particular version:

Update-Package jQuery -ProjectName MyProject -Version 1.8

Update a particular package in all projects of the current solution to the latest version:

Update-Package jQuery

Update a particular package in all projects of the current solution to a particular version:

Update-Package jQuery -version 1.8

Reinstall a particular package in all projects of the current solution:

Update-Package jQuery -reinstall

Update all packages in a project to the latest versions:

Update-Package -ProjectName MyProject

Reinstall all packages in a project:

Update-Package -ProjectName MyProject -Reinstall

Update all packages in all projects of the current solution to the latest versions:

Update-Package

Reinstall all packages in all projects of the current solution:

Update-Package -Reinstall