dotnet/Nerdbank.GitVersioning

How to treat one lib in multi-lib repo differently (always marked as preview)?

egil opened this issue · 5 comments

egil commented

I have a repository that includes multiple libraries. One of the libraries is experimental, so when I do a dotnet pack, I want its version to retain the preview version suffix as with unstable releases, even if the rest of the libraries does not have this.

This is my current version.json:

// https://github.com/bUnit-dev/bUnit/blob/main/version.json
{
  "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
  "version": "1.26-preview",
  "assemblyVersion": {
    "precision": "revision"
  },
  "nuGetPackageVersion": {
    "semVer": 2.0
  },
  "publicReleaseRefSpec": [
    "^refs/heads/stable$"
  ],
  "cloudBuild": {
    "buildNumber": {
      "enabled": true
    }
  },
  "release": {
    "branchName": "release/v{version}",
    "firstUnstableTag": "preview"
  },
  "pathFilters": [
    "./src"
  ]
}

The project I want to always be marked as experimental/preview is this: https://github.com/bUnit-dev/bUnit/blob/main/src/bunit.web.query/bunit.web.query.csproj

The best way you can do it today is to add a src/bunit.web.query/version.json file with content like this:

{
 "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
  "version": "1.26-preview",
  "inherit": "true"
}

The inherit part keeps you from having to double up on everything. You'll still have to double up on the version number, unfortunately. But having the unique copy of the version property allows that one project to retain the -preview suffix.

egil commented

I'm currently managing versions by doing nbgv prepare-release --versionIncrement minor at the root level. Do I need to change that with the nested version.json?

Yes, you'd have to edit that one manually.
Not a great story, to be sure. I'm open to proposals to improve it.

egil commented

Ok.

Just so I understand correctly, if I run dotnet pack from my stable branch with the version number in the root version.json file is 1.25, i.e. without the -preview suffix, and if I add a version.json in my "experimental" projects folder and it has the version set to 1.25-preview, will dotnet pack will create a preview package for that project?

Or so I need to override other properties too?

Just the additional version.json file should do it. But it needs to be committed before you'll see the full effect, as normal for such a file.