在构建过程中修改TFS 2015 BuildNumber [英] Modify TFS 2015 BuildNumber during build process

本文介绍了在构建过程中修改TFS 2015 BuildNumber的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在TFS下存储了一些嵌入式C软件,并且还有一个相应的TFS构建定义,可以成功检出代码并使用相关的编译器对其进行构建.所以要清楚一点,尽管这是TFS,但我不是在构建.NET应用程序.

I have some embedded C software stored under TFS and also have a corresponding TFS build definition that successfully checks out the code and builds it using the relevant compilers. So just to be clear, although this is TFS, I'm not building a .NET application.

现在我可以进行构建了,我正在尝试提供应该与构建过程链接的整体软件版本支持.我目前的目标如下:

Now that I have the build working, I'm trying to provide overall software versioning support which should be linked to the build process. My current aim is as follows:

正在构建的源代码具有一个头文件,该头文件对三个变量(主要版本,次要版本和内部版本号)具有#defines.然后,该头文件用于在编译时将版本号烘烤到软件中.概念是,开发人员负责在开发过程中仅更新主要和次要版本号.内部版本号始终保持为0,开发人员不应对其进行修改.

The source code that is being built has a header file that has #defines for three variables, Major Version, Minor Version and Build Number. This header file is then used to baked the version number in to the software at compile time. The concept is that the developer is responsible for updating only the major and minor version numbers as part of the development. The build number always remains at 0 in the source and should not be modified by the developer.

如果开发人员在自己的计算机上本地生成构建,则将按照代码中的定义设置主要版本和次要版本,但是内部版本号将保持为0,这表明存在不受控制的内部版本.但是,对于服务器上的正式内部版本,我希望TFS自动增加内部版本号,以便随后指定相同主版本和次要版本的内部版本会导致内部版本号增加,从而提供整体唯一的版本描述符.

In the instance that a developer produces a build locally on their own machine, the major and minor version will be set as defined in the code, but the build number will remain at 0 which gives an indication of a non-controlled build. However, for official builds on the server, I'd like TFS to increment the build number automatically, so that subsequent builds with the same major and minor version specified, result in an increment of the build number to provide an overall unique version descriptor.

经过一番阅读之后,我如何看待这项工作是如何将TFS内部版本号格式定义为如下所示: $ MajorVersion.$ MinorVersion.$(Rev:.rr)其中MajorVersion和MinorVersion是我在构建过程中定义的变量.

After doing a bit of reading, how I specifically see this working is to define the TFS build number format as something like the following: $MajorVersion.$MinorVersion.$(Rev:.rr) where MajorVersion and MinorVersion are variables that I define as part of the build process.

我意识到修订版基于整个内部版本号格式保持唯一性.因此,我认为至关重要的是,从源代码中提取主要版本和次要版本,并在试图评估修订版和更大的内部版本号之前填充两个内部版本变量.我创建了一个Powershell脚本,使用正则表达式从头文件中提取主要版本和次要版本,然后在脚本中设置变量.

I realized that the revision maintains uniqueness based on the entire build number format. So I thought it was vital that I extract the major and minor versions from the source code and populate the two build variables prior to trying to evaluate the revision and wider build number. I've created a Powershell script to extract the major and minor versions from the header file using regular expressions and then set the variables from within the script.

现在终于可以解决问题了.看来我的方法有缺陷.一旦我将构建放入队列中,就立即评估TFS内部版本号,似乎是给排队的构建起一个名字.在这一阶段,我无法运行我的脚本来提取主要版本和次要版本,因此也得到了不正确的修订号.因此,根据上述我之前提到的内部版本号格式,我最终得到内部版本号和结果名称,如"..01"或"0.0.01",这取决于我是否在构建定义中初始化了主要变量和次要变量.

Now finally to the problem. It seems my approach is flawed. As soon as I queue the build, the TFS build number is evaluated immediately, seemingly to give a name to the queued build. At this stage, I've been unable to run my script to extract the major and minor versions and hence also get an incorrect revision number. So based on my previously mentioned build number format above, I end up with a build number and result name of something like "..01" or "0.0.01" depending on whether I initialize the major and minor variables in the build definition.

那么,有人能通过Powershell构建步骤从源头上读取我的主要版本和次要版本之后,谁能看到一种方法来推迟对TFS内部版本号的评估?如果可以,则应根据实际的主要和次要版本正确计算修订.然后,我将使用另一个脚本在头文件中仅设置内部版本号#define以匹配TFS内部版本号的修订.另外,似乎TFS使用内部版本号作为排队的内部版本的名称,我不确定如何处理此问题,因为我不知道最终进入队列的TFS内部版本号.可以在构建过程中修改名称吗?

So can anyone see a way that I can defer the evaluation of the TFS build number until after I've had a chance to read my major and minor verisons from source via a Powershell build step? If I can do this, the revision should be calculated correctly based on the real major and minor versions. I'll then use another script to set only the Build number #define in my header file to match the revision in the TFS build number. Also, as it seems that TFS uses the build number as the name of the queued build, I'm not sure how I can deal with this since I don't know the final TFS build number at the point the build is queued. Can the name be modified during the build process?

请帮助.我认为我的想法很简单,但我正在努力使其与其他非常出色的TFS 2015构建系统一起实现.

Please help. I think my idea is fairly simple but I'm struggling to make it happen with the otherwise very good TFS 2015 build system.

推荐答案

TL; DR;您可以像上面一样使用内部版本号格式,也可以创建自定义内部版本号...不能同时使用.

TL;DR; You can either use the build number format as you have above, or create a custom build number...not both.

使用Team Build,您可以在构建期间的任何时候通过输出"## vso [build.updatebuildnumber] 1.2.3.4"来更新构建号.到构建期间的日志.

With Team Build you can update the build number at any time during the build by outputing "##vso[build.updatebuildnumber]1.2.3.4" to the log during the build.

您可以在此处查看日志记录命令的完整列表 https://github.com/Microsoft/vso -agent-tasks/blob/master/docs/authoring/commands.md

You can see the full list of logging commands here https://github.com/Microsoft/vso-agent-tasks/blob/master/docs/authoring/commands.md

这将更新内部版本号&名称.

This will update the build number & name.

您遇到的不利之处是您无法再使用一直尝试使用的自动递增编号.您需要自己提供版本号,然后使用上面的输出将其传回.

The down side that you have run into is that you can no longer use the auto-incrementing number that you have been trying to use. You need to come up with the version number yourself, and then pass it back using the output above.

但是,您可以使用自动递增功能来使构建系统创建版本号,然后将其写入所需的位置.

You can however use the auto-incrementing to have the build system create a version number and then write it into the locations you need..

https://www.visualstudio.com/en-us/docs/build/scripts/

如果您使用的是Git,则可以在构建期间使用GitVersion为您创建语义或自动递增的数字.或者,您可以使用文件来明确指定编号.

If you are using Git you can use GitVersion to create Semantic or auto-incrementing numbers for you during a build. Or you can use a file to specify the number explicitly.

这篇关于在构建过程中修改TFS 2015 BuildNumber的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆