Skip to content

Add --what-if switch to nbgv tag command to preview tag names#1287

Merged
AArnott merged 2 commits into
mainfrom
copilot/add-get-tag-name-feature
Oct 15, 2025
Merged

Add --what-if switch to nbgv tag command to preview tag names#1287
AArnott merged 2 commits into
mainfrom
copilot/add-get-tag-name-feature

Conversation

Copilot AI commented Oct 15, 2025

Copy link
Copy Markdown
Contributor

Summary

Adds a --what-if switch to the nbgv tag command that outputs the tag name that would be created without actually creating the tag.

Motivation

Users need to know what tag name will be generated for a specific commit without creating the tag. This is particularly useful in CI/CD workflows where tag names need to be passed between pipeline steps or jobs. Previously, users had to either:

  1. Hardcode the tag format (duplicating the format from version.json)
  2. Create the tag just to get its name

This creates a maintenance burden as any changes to version.json tag format require updating hardcoded values in workflow files.

Changes

  • Added --what-if boolean option to the nbgv tag command
  • When specified, the command calculates and outputs the tag name to stdout without creating the tag
  • Interactive commit selection (when multiple commits match a version) still works with --what-if
  • The last line written to stdout is always the tag name

Usage

# Preview tag name without creating it
$ nbgv tag --what-if
v1.2.3

# Works with custom tag formats defined in version.json
$ nbgv tag --what-if
release-1.2.3

# Can be used with specific version or commit
$ nbgv tag 1.2.3 --what-if
v1.2.3

# Normal tag creation unchanged
$ nbgv tag
v1.2.3 tag created at abc123...
Remember to push to a remote: git push origin v1.2.3

Example Workflow Integration

- name: Get tag name
  id: get-tag
  run: echo "tag=$(nbgv tag --what-if)" >> $GITHUB_OUTPUT

- name: Use tag in later step
  run: echo "Will create tag ${{ steps.get-tag.outputs.tag }}"
  
- name: Create tag when ready
  run: nbgv tag

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: curl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature] Provide a way to get the tag name for the current context without actually creating the tag</issue_title>
<issue_description>We have a situation where we want to know what the tag name will be for a certain codebase/folder but we want to delay the creation of said tag to later.

The nbgv tag command only provides a means to tag a commit on the spot using the rules from the closest version.json. The variables created by the NuGet package also don't include the tag name today, even with "setAllVariables": true.

I would like to propose that the tag name be output in either one or both of these approaches, so that we can read what the tag name value will be, and be able to pass it along to a future step (we currently use this information in a future GitHub Actions job, so we pass it as a step/job output).

Perhaps for variables, there could be a new NBGV_TagName variable. And for nbgv tag, something similar to nbgv get-version could be done (either as a separate get-tag command, or an option on the existing tag command).

Our workaround today is to fully hardcode the tag format, which creates an obvious duplication with the specified format in version.json: if we end up changing the format on version.json, our GitHub workflow goes out of sync and would need to be updated separately.</issue_description>

<agent_instructions>Let's deliver on this request by adding a --what-if switch to the nbgv tag command. When specified, the tag will not be created, and the only text written to stdout should be the name of the tag.

If --what-if is used in a case where we would need to interrogate the user to pick commits, we should still write that out in an interactive way. The last line written would still be the name of the tag.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #1265


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
Copilot AI changed the title [WIP] Add feature to retrieve future tag name without creation Add --what-if switch to nbgv tag command to preview tag names Oct 15, 2025
Copilot AI requested a review from AArnott October 15, 2025 18:33
@AArnott AArnott added this to the v3.9 milestone Oct 15, 2025
@AArnott AArnott marked this pull request as ready for review October 15, 2025 18:55
@AArnott AArnott enabled auto-merge October 15, 2025 18:55
@AArnott AArnott added this pull request to the merge queue Oct 15, 2025
Merged via the queue into main with commit 66144cf Oct 15, 2025
23 checks passed
@AArnott AArnott deleted the copilot/add-get-tag-name-feature branch October 15, 2025 19:32
craigktreasure pushed a commit to craigktreasure/Treasure.Utils that referenced this pull request May 2, 2026
Updated [nbgv](https://github.com/dotnet/Nerdbank.GitVersioning) from
3.6.146 to 3.9.50.

<details>
<summary>Release notes</summary>

_Sourced from [nbgv's
releases](https://github.com/dotnet/Nerdbank.GitVersioning/releases)._

## 3.9.50

## What's Changed
* Add `versionHeightOffsetAppliesTo` property to version.json by
@​Copilot in dotnet/Nerdbank.GitVersioning#1279
* Fix `nbgv prepare-release` command to honor inheriting version.json
files by @​AArnott in
dotnet/Nerdbank.GitVersioning#1281
* Automatically disable git engine for Dependabot environments by
@​Copilot in dotnet/Nerdbank.GitVersioning#1284
* Add --what-if switch to nbgv tag command to preview tag names by
@​Copilot in dotnet/Nerdbank.GitVersioning#1287
* Auto-disable git engine for GitHub Copilot environments by @​Copilot
in dotnet/Nerdbank.GitVersioning#1291
* Allow uppercase letters in pre-release version identifiers by
@​Copilot in dotnet/Nerdbank.GitVersioning#1293

## New Contributors
* @​micheloliveira-com made their first contribution in
dotnet/Nerdbank.GitVersioning#1277

**Full Changelog**:
dotnet/Nerdbank.GitVersioning@v3.8.118...v3.9.50

## 3.9.37-alpha

## What's Changed
* Auto-disable git engine for GitHub Copilot environments by @​Copilot
in dotnet/Nerdbank.GitVersioning#1291


**Full Changelog**:
dotnet/Nerdbank.GitVersioning@v3.9.32-alpha...v3.9.37-alpha

## 3.9.32-alpha

## What's Changed

* Automatically disable git engine for Dependabot environments by
@​Copilot in dotnet/Nerdbank.GitVersioning#1284
* Add --what-if switch to nbgv tag command to preview tag names by
@​Copilot in dotnet/Nerdbank.GitVersioning#1287

**Full Changelog**:
dotnet/Nerdbank.GitVersioning@v3.9.17-alpha...v3.9.32-alpha

## 3.9.17-alpha

## What's Changed
* Fix `nbgv prepare-release` command to honor inheriting version.json
files by @​AArnott in
dotnet/Nerdbank.GitVersioning#1281


**Full Changelog**:
dotnet/Nerdbank.GitVersioning@v3.9.15-alpha...v3.9.17-alpha

## 3.9.15-alpha

## What's Changed

* Add `versionHeightOffsetAppliesTo` property to version.json by
@​Copilot in dotnet/Nerdbank.GitVersioning#1279

## New Contributors
* @​micheloliveira-com made their first contribution in
dotnet/Nerdbank.GitVersioning#1277

**Full Changelog**:
dotnet/Nerdbank.GitVersioning@v3.8.118...v3.9.15-alpha

## 3.8.118

## Fixes

* Don't try to disable CA2243 warnings in the generated version info
files for F# by @​Numpsy in
dotnet/Nerdbank.GitVersioning#1174
* Catch a more general JsonException. by @​ANGEL-OF-DEV in
dotnet/Nerdbank.GitVersioning#1191
* Retarget links to migrated docs by @​bencemali in
dotnet/Nerdbank.GitVersioning#1193
* Check MSBuild items with case insensitivity by @​AArnott in
dotnet/Nerdbank.GitVersioning#1213
* Fix inconsistent CLI output format for GitCommitDate by @​Copilot in
dotnet/Nerdbank.GitVersioning#1246
* Fix version height computed as 0 when project path has non-canonical
casing by @​Copilot in
dotnet/Nerdbank.GitVersioning#1244
* When generating the GitCommitDate field in the AssemblyInfo for F#, d…
by @​Numpsy in
dotnet/Nerdbank.GitVersioning#1253
* Only do Android version check on applications by @​dotMorten in
dotnet/Nerdbank.GitVersioning#1256
* Fix `nbgv set-version` to write to the best version.json file in scope
by @​AArnott in
dotnet/Nerdbank.GitVersioning#1264

## Enhancements

* Add msbuild-provided prerelease identifiers by @​AArnott in
dotnet/Nerdbank.GitVersioning#1153
* Add support for stamping version on server.json for MCP servers with
0.0.0-placeholder replacement by @​Copilot in
dotnet/Nerdbank.GitVersioning#1270 and by
@​AArnott in dotnet/Nerdbank.GitVersioning#1271
* Add option to set / skip CloudBuildNumber by @​MattKotsenas in
dotnet/Nerdbank.GitVersioning#1190
* Add Central Package Management (CPM) support to nbgv install command
by @​Copilot in
dotnet/Nerdbank.GitVersioning#1208
* Add --public-release argument to nbgv get-version command by @​Copilot
in dotnet/Nerdbank.GitVersioning#1245
* Invoke PrivateP2PCaching.proj fewer times by @​AArnott in
dotnet/Nerdbank.GitVersioning#1263

## Other changes

* Update dependency Cake.Core to v5 by @​renovate[bot] in
dotnet/Nerdbank.GitVersioning#1183

## New Contributors
* @​ANGEL-OF-DEV made their first contribution in
dotnet/Nerdbank.GitVersioning#1191
* @​bencemali made their first contribution in
dotnet/Nerdbank.GitVersioning#1193
* @​Copilot made their first contribution in
dotnet/Nerdbank.GitVersioning#1208
* @​dotMorten made their first contribution in
dotnet/Nerdbank.GitVersioning#1256
* @​emmanuel-ferdman made their first contribution in
dotnet/Nerdbank.GitVersioning#1145

**Full Changelog**:
dotnet/Nerdbank.GitVersioning@v3.7.115...v3.8.118

## 3.8.106-alpha

## What's Changed

### Enhancements

* Add option to set / skip CloudBuildNumber by @​MattKotsenas in
dotnet/Nerdbank.GitVersioning#1190
* Add Central Package Management (CPM) support to nbgv install command
by @​Copilot in
dotnet/Nerdbank.GitVersioning#1208
* Add --public-release argument to nbgv get-version command by @​Copilot
in dotnet/Nerdbank.GitVersioning#1245
* Invoke PrivateP2PCaching.proj fewer times by @​AArnott in
dotnet/Nerdbank.GitVersioning#1263

### Fixes

* Catch a more general JsonException. by @​ANGEL-OF-DEV in
dotnet/Nerdbank.GitVersioning#1191
* Retarget links to migrated docs by @​bencemali in
dotnet/Nerdbank.GitVersioning#1193
* Check MSBuild items with case insensitivity by @​AArnott in
dotnet/Nerdbank.GitVersioning#1213
* Fix inconsistent CLI output format for GitCommitDate by @​Copilot in
dotnet/Nerdbank.GitVersioning#1246
* Fix version height computed as 0 when project path has non-canonical
casing by @​Copilot in
dotnet/Nerdbank.GitVersioning#1244
* When generating the GitCommitDate field in the AssemblyInfo for F#, d…
by @​Numpsy in
dotnet/Nerdbank.GitVersioning#1253
* Only do Android version check on applications by @​dotMorten in
dotnet/Nerdbank.GitVersioning#1256
* Fix `nbgv set-version` to write to the best version.json file in scope
by @​AArnott in
dotnet/Nerdbank.GitVersioning#1264

### Other changes

* Update dependency Cake.Core to v5 by @​renovate[bot] in
dotnet/Nerdbank.GitVersioning#1183

## New Contributors
* @​ANGEL-OF-DEV made their first contribution in
dotnet/Nerdbank.GitVersioning#1191
* @​bencemali made their first contribution in
dotnet/Nerdbank.GitVersioning#1193
* @​Copilot made their first contribution in
dotnet/Nerdbank.GitVersioning#1208
* @​dotMorten made their first contribution in
dotnet/Nerdbank.GitVersioning#1256

**Full Changelog**:
dotnet/Nerdbank.GitVersioning@v3.8.38-alpha...v3.8.106-alpha

## 3.8.38-alpha

## Fixes

* Don't try to disable CA2243 warnings in the generated version info
files for F# by @​Numpsy in
dotnet/Nerdbank.GitVersioning#1174

## Enhancements

* Add msbuild-provided prerelease identifiers by @​AArnott in
dotnet/Nerdbank.GitVersioning#1153

## New Contributors
* @​emmanuel-ferdman made their first contribution in
dotnet/Nerdbank.GitVersioning#1145

**Full Changelog**:
dotnet/Nerdbank.GitVersioning@v3.7.115...v3.8.38-alpha

## 3.7.115


## Changes:


### Fixes:


* #​1151: Fix exception thrown for repos cloned without tags
* #​1150: Getting the build version fails for repositories cloned with
--no-tags

### Enhancements:


* #​318: Emit a warning when SemVer 2.0 format version is specified with
explicitly selecting SemVer 1.0.


This list of changes was [auto
generated](https://dev.azure.com/andrewarnott/OSS/_build/results?buildId=11184&view=logs).

## 3.7.112

## What's Changed
* Fix typo in the Cake extension documentation comment by @​kapsiR in
dotnet/Nerdbank.GitVersioning#939
* Retarget from net462 to net472 by @​AArnott in
dotnet/Nerdbank.GitVersioning#941
* Add option to include package version in `ThisAssembly` class by
@​AArnott in dotnet/Nerdbank.GitVersioning#976
* Make GitPackCache include ObjectType by @​georg-jung in
dotnet/Nerdbank.GitVersioning#942
* Add git-based detection of tags at HEAD to improve PublicRelease
detection by @​georg-jung in
dotnet/Nerdbank.GitVersioning#876
* Remove package reference to Moq by @​AArnott in
dotnet/Nerdbank.GitVersioning#1003
* Allow customizing commit message pattern in `prepare-release` command
by @​fmacavilca in
dotnet/Nerdbank.GitVersioning#996
* AssemblyVersionInfo: Use `global::` for all references to types in
`System.*` namespaces. by @​alexrp in
dotnet/Nerdbank.GitVersioning#1012
* Invert `Language` special-casing to handle *supported* programming
languages. by @​alexrp in
dotnet/Nerdbank.GitVersioning#1021
* Fix lookup of tags in the presence of lightweight tags by @​Rob-Hague
in dotnet/Nerdbank.GitVersioning#1029
* ReleaseManager: do not reset VersionHeightOffset if it equals to -1 by
@​DmitryZhelnin in
dotnet/Nerdbank.GitVersioning#1100
* fix GitCommitDate being author date rather than commit date by
@​DmitryZhelnin in
dotnet/Nerdbank.GitVersioning#1103
* Ensure GetBuildVersion runs before Clean by @​MattKotsenas in
dotnet/Nerdbank.GitVersioning#1107
* Avoid inexact stream reads by @​AArnott in
dotnet/Nerdbank.GitVersioning#1127
* Introduce `NBGV_UseAssemblyVersionInNativeVersion` msbuild property by
@​vitezslav-popovsky-solarwinds in
dotnet/Nerdbank.GitVersioning#1125

## New Contributors
* @​fmacavilca made their first contribution in
dotnet/Nerdbank.GitVersioning#996
* @​Rob-Hague made their first contribution in
dotnet/Nerdbank.GitVersioning#1029
* @​DmitryZhelnin made their first contribution in
dotnet/Nerdbank.GitVersioning#1100
* @​MattKotsenas made their first contribution in
dotnet/Nerdbank.GitVersioning#1107
* @​github-actions made their first contribution in
dotnet/Nerdbank.GitVersioning#1135
* @​vitezslav-popovsky-solarwinds made their first contribution in
dotnet/Nerdbank.GitVersioning#1125

**Full Changelog**:
dotnet/Nerdbank.GitVersioning@v3.6.146...v3.7.112

## 3.7.77-alpha

## What's Changed
* Bump Microsoft.Build.Locator from 1.6.10 to 1.7.8 by @​dependabot in
dotnet/Nerdbank.GitVersioning#1062
* Bump Newtonsoft.Json.Schema from 3.0.16 to 4.0.1 by @​dependabot in
dotnet/Nerdbank.GitVersioning#1063
* Bump node.js version and switch from camel-case to change-case by
@​AArnott in dotnet/Nerdbank.GitVersioning#1077
* Switch System.Text.Json to non-vulnerable version by @​AArnott in
dotnet/Nerdbank.GitVersioning#1074


**Full Changelog**:
dotnet/Nerdbank.GitVersioning@v3.7.70-alpha...v3.7.77-alpha

## 3.7.70-alpha


## Changes:


### Fixes:


* #​250: GetBuildVersion fails with NullReferenceException when version
is missing
* #​943: Upgrading from 3.5.119 to 3.6.132 breaks commit id for NPM
* #​935: BuildingRef is incorrectly populated on Bitbucket pipelines

### Enhancements:


* #​251: GetBuildVersion fails with NotSupportedException when version
is a simple number
* #​233:  Major, Minor and Patch version parts as separate variables

### Others:


* #​1056: Bump BenchmarkDotNetVersion from 0.13.10 to 0.13.12
* #​1057: Bump Newtonsoft.Json.Schema from 3.0.15 to 3.0.16
<details><summary><b>See More</b></summary>

* #​1039: Merge latest Library.Template
* #​1050: Merge v3.6 to main
* #​1046: Bump typescript from 5.4.3 to 5.4.5 in
/src/nerdbank-gitversioning.npm
* #​265: Add AssemblyInfo.GitCommitId property
* #​264: Remove `g` prefix in commit IDs
* #​255: Fix for issue #​149 - Adding F# support for AssemblyInfo
generation
* #​252: Not working in .NET Core docker image
* #​254: Update Cake.Core dependency to 0.30.0
* #​1024: Change F# AssemblyInfo generation to always include a do()
after the …
* #​245: Fix attribute name in readme
* #​241: Switch to Azure Pipelines
* #​242: Remove typings to fix build break
* #​243: Capture all nupkg files as artifacts
* #​240: is it possible to update LibGit2Sharp package version from
0.25.2 to 0.26.0-preview-0054?
* #​238: Upgrade Typescript + npm cleanup
* #​236: npm setPackageVersion semver2 support
* #​235: Add a few properties for easier processing at the command line
* #​231: Remove names from regex capture groups in version.schema.json
* #​232: NPM/Yarn-only way of versioning packages
* #​234: Add cake-contrib user to Cake.GitVersioning NuGet package
* #​994: Fix build.ps1 script
* #​992: I have a problem building the solution
* #​982: Fix WPF incremental build
* #​175: NB.GV defeats incremental build for .NET SDK style WPF projects
* #​945: Revert "Drop BuildMetadata from NPM package version"
* #​938: Downgrade Cake.Core to v2.3.0
 ... (truncated)

## 3.7.62-alpha

## What's Changed
* AssemblyVersionInfo: Use `global::` for all references to types in
`System.*` namespaces. by @​alexrp in
dotnet/Nerdbank.GitVersioning#1012
* Invert `Language` special-casing to handle *supported* programming
languages. by @​alexrp in
dotnet/Nerdbank.GitVersioning#1021
* Fix lookup of tags in the presence of lightweight tags by @​Rob-Hague
in dotnet/Nerdbank.GitVersioning#1029
* Bump NuGet.PackageManagement from 6.7.0 to 6.9.1 by @​dependabot in
dotnet/Nerdbank.GitVersioning#1034
* Bump Cake.Core from 3.0.0 to 3.2.0 by @​dependabot in
dotnet/Nerdbank.GitVersioning#999

## New Contributors
* @​Rob-Hague made their first contribution in
dotnet/Nerdbank.GitVersioning#1029

**Full Changelog**:
dotnet/Nerdbank.GitVersioning@v3.7.48-alpha...v3.7.62-alpha

## 3.7.48-alpha

## What's Changed

### Features
- Added option to include package version in `ThisAssembly` class. [PR
#​976](dotnet/Nerdbank.GitVersioning#976)
- Retargeted from .NET Framework 4.6.2 to 4.7.2 for enhanced
compatibility and performance. [PR
#​941](dotnet/Nerdbank.GitVersioning#941)
- Added git-based detection of tags at HEAD to improve PublicRelease
detection. [PR
#​876](dotnet/Nerdbank.GitVersioning#876)
- Allowed customizing commit message pattern in `prepare-release`
command. [PR
#​996](dotnet/Nerdbank.GitVersioning#996)
- Updated to .NET 8 SDK, aligning with the latest technology standards.
[PR #​1002](dotnet/Nerdbank.GitVersioning#1002)

### Fixes
- Fixed a typo in the Cake extension documentation comment. [PR
#​939](dotnet/Nerdbank.GitVersioning#939)
- Made GitPackCache include ObjectType for more accurate caching. [PR
#​942](dotnet/Nerdbank.GitVersioning#942)

## New Contributors
- @​fmacavilca made their first contribution. [View
Contribution](dotnet/Nerdbank.GitVersioning#996)

[**Full
Changelog**](dotnet/Nerdbank.GitVersioning@v3.6.133...v3.7.48-alpha)

Commits viewable in [compare
view](dotnet/Nerdbank.GitVersioning@v3.6.146...v3.9.50).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=nbgv&package-manager=nuget&previous-version=3.6.146&new-version=3.9.50)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Provide a way to get the tag name for the current context without actually creating the tag

2 participants