6

Closed

Version option for nuget.exe CLI Pack command

description

I would like the ability to override the Version specified in the .nuspec file from the nuget.exe command line.

Ex: nuget.exe pack mypackage.nuspec -version 1.2.3

would create a package with version 1.2.3, regardless of the version in the .nuspec file.

This will greatly simply automated build scenarios, and avoid duplication (most projects already store version information somewhere else in their code tree). I shouldn't have to update my VERSION.txt and .nuspec file every time I increment the version.

Fortunately, it looks like it would be easy to implement (I'll volunteer if others agree it should be done). I would probably add the following line immediately after the PackageBuilder is constructed in PackCommand.ExecuteCommand:

if (!String.IsNullOrEmpty(Version)) builder.Version = new Version(Version);
Closed Mar 14, 2011 at 5:41 PM by drewmiller
Verified:
  • I can install without the -version flag and the latest version is installed
  • I can install a specific version with the -version flag
  • I get a helpful error if I specify an invalid version
  • -Version and -ExcudeVersion work together
  • If I enter an invalid version string I get a helpful error message
QUESTION: Why not alias the -Version option to v?

comments

joshuaflanagan wrote Mar 2, 2011 at 3:29 AM

FYI - I briefly considered making it more flexible so that any piece of metadata could be overridden via CLI options, but ruled that out. The only metadata that realistically would be frequently changing is the version. Supporting all metadata would be unnecessarily complex.

blairdavidson wrote Mar 2, 2011 at 4:01 AM

Good idea

mcdon wrote Mar 2, 2011 at 6:31 PM

When overriding the version number, the new version number should be saved to the nuspec file as well. The build server would then commit this change back to the repository. This way the new version number is saved in the case of a rebuild. This would help make a build repeatable down to the version number the build server generates.

mcdon wrote Mar 2, 2011 at 6:32 PM

This option should also be provided in the NuGet msbuild task

Haacked wrote Mar 3, 2011 at 1:05 AM

We're actually considering something like this, but more full featured. Allowing replacement strings in NuSpec. I'll keep you posted.

joshuaflanagan wrote Mar 4, 2011 at 12:46 AM

I disagree about writing the new version back to the nuspec file. I think the nuspec should just be considered one (of possibly many) inputs needed to define a package. I don't think its useful to have a file history in source control for every version increment. Presumably you have a way of determining the version as part of your build process. As long as that is deterministic, you will have a repeatable build.

joshuaflanagan wrote Mar 4, 2011 at 12:50 AM

Regarding replacement strings - I'll reiterate that I think its less important that you be able to modify the nuspec file itself. You just need to provide a way to set the various properties of the model (PackageBuilder). For example, there should be an MSBuild task that has input properties for each of the metadata items in the nuspec file - not just the path to the file itself. Is there any reason I shouldn't be able to build a package without a nuspec file if I provide all of the necessary information?

joshuaflanagan wrote Mar 4, 2011 at 4:19 AM

I've implemented this feature in my fork. Grab it if you want it:
https://hg01.codeplex.com/forks/joshuaflanagan/nuget

Haacked wrote Mar 7, 2011 at 11:13 PM

Matt, can you investigate this change and pull it in if it works for you? We talked about doing something more general, but for now, this is a nice targetted change we could take now while we plan that other feature.

dfowler wrote Mar 9, 2011 at 5:46 PM

Fixed in CS 3e9aa42bbdd2