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?
If you look at https://github.com/Microsoft/vsts-tasks/blob/master/Tasks/NugetPackager/NuGetPackager.ps1 :
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.
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
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: