We are using pipelines in Azure DevOps to build nuget-packages and push them in our feed.
Context:
In our Build-Pipeline, we have a task which uses giversion to generate the version number for the NuGet package:
- task: gitversion/execute@0 displayName: Calculate GitVersion inputs: useConfigFile: true configFilePath: './.Pipelines/GitVersion.yml'
Our GitVersion.yml-File looks as follows:
assembly-versioning-scheme: MajorMinorPatchassembly-file-versioning-scheme: MajorMinorPatchTagassembly-informational-format: '{InformationalVersion}'mode: Mainlineincrement: Patchcontinuous-delivery-fallback-tag: citag-prefix: '[vV]'major-version-bump-message: '\+semver:\s?(breaking|major)'minor-version-bump-message: '\+semver:\s?(feature|minor)'patch-version-bump-message: '\+semver:\s?(fix|patch)'no-bump-message: '\+semver:\s?(none|skip)'legacy-semver-padding: 4build-metadata-padding: 4commits-since-version-source-padding: 4commit-message-incrementing: Enabledcommit-date-format: 'yyyy-MM-dd'ignore: sha: [] commits-before: 2021-01-01T00:00:00merge-message-formats: {}branches: hotfix: regex: ^(hotfix|bugfix)(es)?[/-]
A second task in the same pipeline pushes the nuget-package to the feed:
- task: NuGetCommand@2 displayName: 'Push NuGet Packages' inputs: command: 'push' packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg;!$(Build.ArtifactStagingDirectory)/**/Company.Common.Tests*.nupkg' nuGetFeedType: 'internal' publishVstsFeed: '12345...' allowPackageConflicts: true
Problem:
We have 2 commits:
For the first Commit abc, the pipeline generates an version number ...
{"Major": 4,"Minor": 51,"Patch": 0,"PreReleaseTag": "beta.2","PreReleaseTagWithDash": "-beta.2","PreReleaseLabel": "beta","PreReleaseLabelWithDash": "-beta","PreReleaseNumber": 2,"WeightedPreReleaseNumber": 30002,"BuildMetaData": null,"BuildMetaDataPadded": "","FullBuildMetaData": "Branch.releases-4.51.1-Hotfix.Sha.123456789","MajorMinorPatch": "4.51.0","SemVer": "4.51.0-beta.2","LegacySemVer": "4.51.0-beta2","LegacySemVerPadded": "4.51.0-beta0002","AssemblySemVer": "4.51.0.0","AssemblySemFileVer": "4.51.0.2","FullSemVer": "4.51.0-beta.2","InformationalVersion": "4.51.0-beta.2+Branch.releases-4.51.1-Hotfix.Sha.123456789","BranchName": "releases/4.51.1_Hotfix","EscapedBranchName": "releases-4-51-1-Hotfix","Sha": "123456789","ShortSha": "33b4550","NuGetVersionV2": "4.51.0-beta0002","NuGetVersion": "4.51.0-beta0002","NuGetPreReleaseTagV2": "beta0002","NuGetPreReleaseTag": "beta0002","VersionSourceSha": "1234567890","CommitsSinceVersionSource": 2,"CommitsSinceVersionSourcePadded": "0002","UncommittedChanges": 0,"CommitDate": "2024-09-17"}
...and pushes the package successfully to the feed:
The second commit xyz (note: it is an pull-request) accidentally produces the same version number for a new nuget-package, despite some changes:
{"Major": 4,"Minor": 51,"Patch": 0,"PreReleaseTag": "beta.2","PreReleaseTagWithDash": "-beta.2","PreReleaseLabel": "beta","PreReleaseLabelWithDash": "-beta","PreReleaseNumber": 2,"WeightedPreReleaseNumber": 30002,"BuildMetaData": null,"BuildMetaDataPadded": "","FullBuildMetaData": "Branch.releases-4.51.1-Hotfix.Sha.123456789","MajorMinorPatch": "4.51.0","SemVer": "4.51.0-beta.2","LegacySemVer": "4.51.0-beta2","LegacySemVerPadded": "4.51.0-beta0002","AssemblySemVer": "4.51.0.0","AssemblySemFileVer": "4.51.0.2","FullSemVer": "4.51.0-beta.2","InformationalVersion": "4.51.0-beta.2+Branch.releases-4.51.1-Hotfix.Sha.123456789","BranchName": "releases/4.51.1_Hotfix","EscapedBranchName": "releases-4-51-1-Hotfix","Sha": "123456789","ShortSha": "5426918","NuGetVersionV2": "4.51.0-beta0002","NuGetVersion": "4.51.0-beta0002","NuGetPreReleaseTagV2": "beta0002","NuGetPreReleaseTag": "beta0002","VersionSourceSha": "1234567890","CommitsSinceVersionSource": 2,"CommitsSinceVersionSourcePadded": "0002","UncommittedChanges": 0,"CommitDate": "2024-09-19"}
Therefore, the second task cannot push the package to the feed:
GitVersion seem not to increase the build number of the nuget-package. Why?