Nerdbank.GitVersioning: Q: unable to create release version from tag

I have a version.json file that looks like this:

{
  "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
  "version": "0.9",
  "versionHeightOffset": 2,
  "publicReleaseRefSpec": [
    "^refs/tags/rel/\\d+\\.\\d+\\.\\d+"
  ]
}

When I try to build from a tag named rel/0.9.2 I expect the nuget package to be versioned 0.9.2, but it is versioned 0.9.9-g3ed3d4226b.

To reproduce:

git clone https://github.com/tmds/Tmds.DBus.git
cd Tmds.DBus/
git checkout bump_092
git tag rel/0.9.2
git checkout rel/0.9.2
dotnet pack -c Release src/Tmds.DBus

It’s not clear what I’m doing wrong, or maybe I misunderstand some fields in version.json?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 24 (6 by maintainers)

Most upvoted comments

FYI, I tried a few formats with Nerdbank.GitVersioning v3.4.255 and no “publicReleaseRefSpec”:

“version” in version.json AssemblyFileVersion AssemblyInformationalVersion NuGetPackageVersion
“1.51.0-dev.{height}” “1.51.0.0” “1.51.0-dev.21+3db68092be” “1.51.0-dev-0021-g3db68092be”
“1.51.0.{height}” Error “not a valid semantic version”
“1.51.0-{height}” “1.51.0” “1.51.0-21+0018fc9f88” “1.51.0-0021-g0018fc9f88”
“1.51.0” “1.51.0.22” “1.51.0+58d40d701e” “1.51.0-g58d40d701e”
“1.51” “1.51.21.16034” (16034 is 0x3ea2 from the commit ID) “1.51.21+a23e463e6a” “1.51.21-ga23e463e6a”
“1.51.{height}” Error “not a valid semantic version”
“1.51-{height}” “1.51” “1.51.0-21+82ed498be5” “1.51.0-0021-g82ed498be5”
“1.51-beta.{height}” “1.51” “1.51.0-beta.21+b14392952a” “1.51.0-beta-0021-gb14392952a”

So, it seems impossible to get the version height in both AssemblyFileVersion and AssemblyInformationalVersion while explicitly specifying three components of the version. I did not try "nugetPackageVersion": { "semVer": 2 }.

versionHeightOffset can be used to deal with the first, though it would be easier to be able to set the exact number, instead of having to calculate the offset.

Thinking about it more: it would be interesting to have the version height as the 4th version digit in this case.

This can work without an additional field when the user specifies a 3-number version.

{
  "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
  "version": "0.9.2"
}

Maybe some part of .NET tooling would have issues with the 4-number version?

As this github issue is getting long, and it appears that questions have been answered and no bug identified, I’ll close the issue. If I missed something and there is actually an outstanding issue, please let me know and we can re-open. Or, if the issue was identified halfway through the discussion, just open a new issue to track. 😉

Okay, this is a bit of a late reply since I have had bigger things on my plate until just now(ish) but I had been able to test this in Azure DevOps. With the environment variables in place GitVersioning was able to pick up on the correct tag name structure and ditch the -dev suffix. I was confused since I thought that it pokes at git directly, rather than only relying on environment variables from CI. Thank you for making me aware of that difference.

git checkout tag makes HEAD point to the same commit as the tag; it does not save the name of the tag (except perhaps in a reflog). There could be any number of tags pointing to the same commit and Nerdbank.GitVersioning won’t try to guess. However you can provide the tag name via various “cloud build” environment variables; search for BuildingTag in the sources.