Monday, October 15, 2012

Forcing a NuGet Package to update

By default NuGet skips updating a package when there is no higher version number. This brought us into trouble because we changed a package without updating the version number(only the file version had changed). So all our developers had to remove and re-install the package.

Until NuGet 2.1 there was no way to force an update regardless. NuGet 2.1 addresses this with the ‘reinstall’ flag.

Let’s have a look at the sample from the NuGet 2.1 release notes:

Previous versions of NuGet would result in the following when attempting to update a package that did not have a more recent package version:

PM> Update-Package Moq

No updates available for 'Moq' in project 'MySolution.MyConsole'.

With the reinstall flag, the package will be updated regardless of whether there is a newer version.

PM> Update-Package Moq -Reinstall

Successfully removed 'Moq 4.0.10827' from MySolution.MyConsole.

Successfully uninstalled 'Moq 4.0.10827'.

Successfully installed 'Moq 4.0.10827'.

Successfully added 'Moq 4.0.10827' to MySolution.MyConsole.

1 comment:

Renaud Bompuis said...

That little bit about -Reintall was certainly a most useful trick. Saved me aftger making a mess of deleting /obj and /bin folders in my projects and not realizing that some nuget package data was installed there.
Thanks for the tip.