When I set my TFS 2015 build definition, that is creating a NuGet package, I set the Build Number format with:
$(BuildDefinitionName)_$(Major).$(Minor)$(rev:.r)
Where Major and Minor or just variables that I defined. When I use the step "NuGet Packager", I get the error:
Could not find version number data in BUILD_BUILDNUMBER.
When I use 4 digits, I don't get the error. How do I get it to work with semantic versioning?
I found the solution:
1) You need to get access to your Build Agent machine
2) Navigate to where the Build Agent is installed.
For me --> C:\BuildAgent\tasks\NuGetPackager
3) You will see folder versions, so go into the latest one.
4) Modify the PowerShell script, NuGetPackager.ps1
Find --> $VersionRegex = "\d+.\d+.\d+.\d+"
And replace with --> $VersionRegex = "\d+.\d+.\d+.\d+|\d+.\d+.\d+"
5) And then save the script.
What I am doing is modifying the regular expression to say "Search for the pattern #.#.#.# OR #.#.# in the build number string". Whereas before it was only looking for "#.#.#.#".
Now, when you do your build, the TFS Build Agent will be able parse the build version:
Set workingFolder to default: C:\BuildAgent\tasks\NuGetPackager\0.1.58
Executing the powershell script: C:\BuildAgent\tasks\NuGetPackager\0.1.58\NuGetPackager.ps1
Getting version number from build
BUILD_BUILDNUMBER: Planning.Domain.Library-CI_1.0.7
Version: 1.0.7
If you look at https://github.com/Microsoft/vsts-tasks/blob/master/Tasks/NugetPackager/NuGetPackager.ps1 :
if ($b_versionByBuild)
{
Write-Verbose "Autoversion: Getting version number from build"
##Get Version from Build
# Regular expression pattern to find the version in the build number
# and then apply it to the assemblies
$VersionRegex = "\d+\.\d+\.\d+(?:\.\d+)?"
Support for 3 part build numbers came from this commit:
https://github.com/Microsoft/vsts-tasks/commit/233c112bc06b91964a559090b8acfd4452cdec0b
Before this commit the regular expresion was just \d+\.\d+\.\d+\.\d+
. So maybe you have an outdated task code in your TFS.
I just checked my on-premise TFS 2015. It cannot parse 3 number version.