如何让 TFS 2015 解析 NuGet 包装的 3 位版本控制
当我设置 TFS 2015 构建定义时,即创建 NuGet 包时,我设置了构建编号格式:
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)
$(BuildDefinitionName)_$(Major).$(Minor)$(rev:.r)
其中主要和次要或只是我定义的变量.当我使用步骤NuGet Packager"时,出现错误:
Where Major and Minor or just variables that I defined. When I use the step "NuGet Packager", I get the error:
在 BUILD_BUILDNUMBER 中找不到版本号数据.
Could not find version number data in BUILD_BUILDNUMBER.
当我使用 4 位数字时,我没有收到错误消息.我如何让它与语义版本控制一起工作?
When I use 4 digits, I don't get the error. How do I get it to work with semantic versioning?
我找到了解决方案:
1) 您需要访问您的 Build Agent 机器
1) You need to get access to your Build Agent machine
2) 导航到 Build Agent 的安装位置.对我来说 --> C:\BuildAgent\tasks\NuGetPackager
2) Navigate to where the Build Agent is installed. For me --> C:\BuildAgent\tasks\NuGetPackager
3) 您将看到文件夹版本,因此请进入最新版本.
3) You will see folder versions, so go into the latest one.
4) 修改 PowerShell 脚本 NuGetPackager.ps1
4) Modify the PowerShell script, NuGetPackager.ps1
查找 --> $VersionRegex = "\d+.\d+.\d+.\d+"
Find --> $VersionRegex = "\d+.\d+.\d+.\d+"
并替换为 --> $VersionRegex = "\d+.\d+.\d+.\d+|\d+.\d+.\d+"
And replace with --> $VersionRegex = "\d+.\d+.\d+.\d+|\d+.\d+.\d+"
5) 然后保存脚本.
我正在做的是修改正则表达式以说在内部版本号字符串中搜索模式#.#.#.# OR #.#.#".而之前它只是在寻找#.#.#.#".
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 "#.#.#.#".
现在,当您进行构建时,TFS 构建代理将能够解析构建版本:
Now, when you do your build, the TFS Build Agent will be able parse the build version:
将workingFolder 设为默认:C:\BuildAgent\tasks\NuGetPackager\0.1.58
Set workingFolder to default: C:\BuildAgent\tasks\NuGetPackager\0.1.58
执行powershell脚本:C:\BuildAgent\tasks\NuGetPackager\0.1.58\NuGetPackager.ps1
Executing the powershell script: C:\BuildAgent\tasks\NuGetPackager\0.1.58\NuGetPackager.ps1
从构建中获取版本号
BUILD_BUILDNUMBER:Planning.Domain.Library-CI_1.0.7
BUILD_BUILDNUMBER: Planning.Domain.Library-CI_1.0.7
版本:1.0.7