Nerdbank.GitVersioning: The `nuget pack` command doesn't produce packages with expected version info

Quite likely that this is user error, so would appreciate any pointers.

I have a project using NB.GV 2.0.41, building with msbuild 15 from the master branch, packing using NuGet 4.3.0.

My version.json includes:

  "publicReleaseRefSpec": [
    "^refs/heads/master",
    "^refs/tags/v\\d+\\.\\d+" 
  ]

My .nuspec file includes:

<version>$version$</version>

When I do nuget pack -Build, the resulting file is just MyPackage.1.0.4.nupkg. But NuGet gives me a warning:

WARNING: Issue: Package version not supported on legacy clients.
WARNING: Description: The package version '1.0.4+g2b37059da8' uses SemVer 2.0.0 or components of SemVer 1.0.0 that are not supported on legacy clients. This message can be ignored if the package is not intended for older clients.
WARNING: Solution: Change the package version to a SemVer 1.0.0 string. If the version contains a release label it must start with a letter.

And in fact, the embedded version string in the package does include the git commit hash.

I thought that the point of the publicReleaseRefSpec was to prevent the git hash from appearing in the package (although it does still appear in the AssemblyInformationalVersion is the assembly itself).

Am I misunderstanding, or doing something stupid?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 23 (9 by maintainers)

Commits related to this issue

Most upvoted comments

We found a workaround/solution for our build process.

  1. According to the cloud build documentation there are options to have NB.GV emit variables containing the proper version strings.
  2. According to the nuget pack reference there are options to pass a version into nuget pack command which overrides the version information from the .nuspec file. This avoids the problem that NuGet tries to resolve the package version via the AssemblyInfo.

In Azure DevOps we now use nbgv cloud --all-vars to determine the version for the build label and the version variables. We then use a NuGetCommand@2 to perform a pack command with

  • versioningScheme: byEnvVar
  • versionEnvVar: NBGV_NUGETPACKAGEVERSION

You can probably also just use something like nuget pack -Version %NBGV_NUGETPACKAGEVERSION% or whatever is appropriate in your build system to achieve the same result. Also other version strings are available.

I emailed the NuGet team to point out the issue in the docs.

I’ve never tested NB.GV with nuget pack. I’m not 100% confident I’ll be able to make it work well with nuget pack – it will be conditional on how flexible it is to read various properties, and whether NB.GV can detect that that is the scenario we’re running in.

I’ll leave this issue open to track nuget pack behavior.