Skip to content

[ISSUE]: dotnet pack fails from feature branch as version variables are set incorrectly / {BranchName} is not unescaped #4734

@MichaelSteinecke

Description

@MichaelSteinecke

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

GitVersion package

GitVersion.Tool

GitVersion version

6.4.0

Operating system

Windows

What are you seeing?

In my pipeline, which has been migrated from 5.2.0 to 6.4.0, the creation of the NuGet Package fails with this error PackageVersion string specified '6.9.0-{BranchName}.1+54' is invalid.:

D:\AzureAgent-03\_work\_tool\dotnet\sdk\9.0.306\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(110,5): error MSB4018: The "GetPackOutputItemsTask" task failed unexpectedly. [D:\AzureAgent-03\_work\25\s\Source\Product\Product.Helper\Product.Helper.csproj]
D:\AzureAgent-03\_work\_tool\dotnet\sdk\9.0.306\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(110,5): error MSB4018: System.ArgumentException: PackageVersion string specified '6.9.0-{BranchName}.1+54' is invalid. [D:\AzureAgent-03\_work\25\s\Source\Product\Product.Helper\Product.Helper.csproj]
D:\AzureAgent-03\_work\_tool\dotnet\sdk\9.0.306\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(110,5): error MSB4018:    at NuGet.Build.Tasks.Pack.GetPackOutputItemsTask.Execute() [D:\AzureAgent-03\_work\25\s\Source\Product\Product.Helper\Product.Helper.csproj]
D:\AzureAgent-03\_work\_tool\dotnet\sdk\9.0.306\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(110,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() [D:\AzureAgent-03\_work\25\s\Source\Product\Product.Helper\Product.Helper.csproj]
D:\AzureAgent-03\_work\_tool\dotnet\sdk\9.0.306\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(110,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [D:\AzureAgent-03\_work\25\s\Source\Product\Product.Helper\Product.Helper.csproj]

Generated output:

Command: git -C D:\AzureAgent-03\_work\25\s rev-parse --is-shallow-repository
Command: D:\AzureAgent-03\_work\_tool\GitVersion.Tool\6.4.0\dotnet-gitversion.exe --roll-forward Major D:\AzureAgent-03\_work\25\s /output json
dotnet-gitversion Output:
-------------------
{
  "AssemblySemFileVer": "6.

[gitversion.log](https://github.com/user-attachments/files/23368957/gitversion.log)

9.0.30001",
  "AssemblySemVer": "6.9.0.0",
  "BranchName": "feature/15357-Launcher-Refactoring",
  "BuildMetaData": 54,
  "CommitDate": "2025-11-05",
  "CommitsSinceVersionSource": 54,
  "EscapedBranchName": "feature-15357-Launcher-Refactoring",
  "FullBuildMetaData": "54.Branch.feature-15357-Launcher-Refactoring.Sha.7f7bf893d521126a7abde30763351d5f5a1edf04",
  "FullSemVer": "6.9.0-{BranchName}.1+54",
  "InformationalVersion": "6.9.0--BranchName-.1+54",
  "Major": 6,
  "MajorMinorPatch": "6.9.0",
  "Minor": 9,
  "Patch": 0,
  "PreReleaseLabel": "{BranchName}",
  "PreReleaseLabelWithDash": "-{BranchName}",
  "PreReleaseNumber": 1,
  "PreReleaseTag": "{BranchName}.1",
  "PreReleaseTagWithDash": "-{BranchName}.1",
  "SemVer": "6.9.0-{BranchName}.1",
  "Sha": "7f7bf893d521126a7abde30763351d5f5a1edf04",
  "ShortSha": "7f7bf89",
  "UncommittedChanges": 0,
  "VersionSourceSha": "0ea87b12521f1da626e5acf69401c59e97bf934e",
  "WeightedPreReleaseNumber": 30001
}

After I removed the feature/ from the refspec, the variables have been calculated correctly.

Command: git -C D:\AzureAgent-03\_work\25\s rev-parse --is-shallow-repository
Command: D:\AzureAgent-03\_work\_tool\GitVersion.Tool\6.4.0\dotnet-gitversion.exe --roll-forward Major D:\AzureAgent-03\_work\25\s /output json
dotnet-gitversion Output:
-------------------
{
  "AssemblySemFileVer": "6.9.0.1",
  "AssemblySemVer": "6.9.0.0",
  "BranchName": "15357-Launcher-Refactoring",
  "BuildMetaData": 54,
  "CommitDate": "2025-11-05",
  "CommitsSinceVersionSource": 54,
  "EscapedBranchName": "15357-Launcher-Refactoring",
  "FullBuildMetaData": "54.Branch.15357-Launcher-Refactoring.Sha.7f7bf893d521126a7abde30763351d5f5a1edf04",
  "FullSemVer": "6.9.0-15357-Launcher-Refactoring.1+54",
  "InformationalVersion": "6.9.0-15357-Launcher-Refactoring.1+54",
  "Major": 6,
  "MajorMinorPatch": "6.9.0",
  "Minor": 9,
  "Patch": 0,
  "PreReleaseLabel": "15357-Launcher-Refactoring",
  "PreReleaseLabelWithDash": "-15357-Launcher-Refactoring",
  "PreReleaseNumber": 1,
  "PreReleaseTag": "15357-Launcher-Refactoring.1",
  "PreReleaseTagWithDash": "-15357-Launcher-Refactoring.1",
  "SemVer": "6.9.0-15357-Launcher-Refactoring.1",
  "Sha": "7f7bf893d521126a7abde30763351d5f5a1edf04",
  "ShortSha": "7f7bf89",
  "UncommittedChanges": 0,
  "VersionSourceSha": "0ea87b12521f1da626e5acf69401c59e97bf934e",
  "WeightedPreReleaseNumber": 1
}

My config:

mode: ContinuousDelivery
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-format: '{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber ?? 0}'
assembly-informational-format: '{FullSemVer}'
branches:
  main:
    regex: ^master$|^main$
  feature:
    regex: ^feature(s)?[/-]
  hotfix:
    regex: ^hotfix(es)?[/-]
ignore:
  sha: [ ]

What is expected?

A valid NuGetPackage and correctly set variables for branch feature/15357-Launcher-Refactoring.

Steps to Reproduce

I believe the behavior is due to the branch name
branch feature/15357-Launcher-Refactoring fails
branch 15357-Launcher-Refactoring succeeds.

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

https://pastebin.com/DdsQvFGv

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions