How do I get TFS 2015 to parse 3 digit versioning for NuGet packaging

主宰稳场 提交于 2019-12-12 04:24:02

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/39253285/how-do-i-get-tfs-2015-to-parse-3-digit-versioning-for-nuget-packaging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!