在构建过程中修改 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,Major Version、Minor Version 和 Build Number.然后使用该头文件在编译时将版本号添加到软件中.这个概念是,作为开发的一部分,开发人员只负责更新主要和次要版本号.内部版本号在源代码中始终保持为 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.

那么谁能看到一种方法,我可以推迟对 TFS 内部版本号的评估,直到我有机会通过 Powershell 构建步骤从源代码读取我的主要和次要版本之后?如果我能做到这一点,应该根据真正的主要和次要版本正确计算修订版.然后我将使用另一个脚本在我的头文件中仅设置内部版本号 #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

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

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天全站免登陆