Enhance nuget update -safe


Currently nuget update -safe will update to the latest revision (well, actually to the latest pre-release of the next minor at the moment).

This command could be enhanced to allow fine grained control on which level the update happens;

I propose:
  • nuget update -safe ==> update to the latest revision available
  • nuget update -safe:revision ==> same behavior as the one without flag
  • nuget update -safe:minor ==> update to the latest minor/revision available
  • nuget update -safe:prerelease ==> update to the latest prerelease available
This would help us as we use nuget for distribution of internal components and during the build process the build server updates the dependencies to the latest available prerelease. We can not use the current version of -safe because this would prevent us from doing parallel development of different revisions of a component.

file attachments


FilipDeVos wrote Jul 29, 2013 at 9:46 PM

I am happy to code this if the feature is accepted.

dotnetjunky wrote Jul 30, 2013 at 7:29 AM

I have the feeling this will not be a trivial change. Did you know that you can use the allowedVersions attribute added to the packages.config file to coerce the update versions? I think it will achieve what you want.

FilipDeVos wrote Jul 30, 2013 at 8:43 AM

Keeping this manually in sync in 500+ packages.config files is really not an option.

dotnetjunky wrote Jul 30, 2013 at 7:17 PM

Can you propose how you're going to tackle it if you are to implement this feature?

FilipDeVos wrote Jul 30, 2013 at 9:15 PM

I'll take a look at the code and write out a spec. (Might take a few days)

FilipDeVos wrote Feb 4, 2014 at 10:26 AM

I worked out a bit more how this should work and came up with this command line:
C:\>nuget.exe update -Scope <UpdateScope> 

PS> Update-Package -Scope <UpdateScope>
The UpdateScope will default to "Latest" which means it can go to the latest version. Other options are
  • Major => update to the latest version within this major version
  • Minor => update to the latest version within this minor version
  • Patch/Build => Update to the latest version within this patch version
  • Revision => update to the latest version within this revision (This won't do anything if -Pre is not specified)
An example usage; assume i am using NuGet.Core 2.7.2:
C:\>nuget.exe update NuGet.Core -Scope Major  

PS> Update-Package NuGet.Core -Scope Major  
This will bring me to NuGet.Core 2.8

The old -Safe flag will be a simple alias to "-Scope Minor"

Changes should be restricted to:
  • CommandLine\Commands\UpdateCommand.cs
  • Core\Utility\VersionUtility.cs
  • PowershellCmdlets\UpdatePackageCommand.cs
  • VisualStudio\IVsPackageManager.cs
  • VisualStudio\VsPackageManager.cs
Together with this change I propose to Refactor the "UpdatePackage" and "SafeUpdatePackage" methods in the VsPackageManager class.

I need some feedback on the VsPackageManager class. I can refactor it to be backwards compatible (with Obsolete attributes) or I can refactor it with breaking changes.

JeffHandley wrote Feb 4, 2014 at 9:14 PM

We can spec this out if you are interested in picking it up. It would need to be similar to how we just did the -DependencyVersion switch on Install-Package. There, we have a Lowest, HighestPatch, HighestMinor, and Highest enum for specifying how versions are selected.

What's your timeframe for wanting to start on this?

FilipDeVos wrote Feb 4, 2014 at 10:21 PM

I intended to work on this in the coming days, but I can shift it. The issue is not blocking.

JeffHandley wrote Feb 7, 2014 at 3:20 AM

Thanks, Filip. We'll have Joost de Nijs reach out to you to work on getting a spec produced for this.

joostden wrote Mar 7, 2014 at 6:51 PM

Attached is the spec for modifications to update-package to make use of the new -DependencyVersion switch, and modify slightly the behavior of the existing -safe switch. Let me know if you have any questions.


FilipDeVos wrote Mar 7, 2014 at 9:27 PM

Thank you, I'll read and see what I can do in the coming weeks.