使 TeamCity 版本与 .NET 程序集版本匹配
现在我们的程序集的版本号是 2.0.831.0。据我了解,这是主要版本、次要版本、日期和内部版本号。如果我进行更改并在同一天再次构建,则为 2.0.831.1、2.0.831.2 等。
我的 TeamCity 构建号格式仅为 2.{0},其中 {0} 是一个自动递增的数字,永远持续下去 (2.195 、2.196 等)。
如何使 TeamCity 看起来与程序集版本完全一样?我们希望能够将更改日志与程序集版本关联起来,这样任何人都可以说程序集版本 2.0.831.2 在这些文件中进行了这些更改。
额外信息: 如果重要的话,我们的构建步骤使用“Visual Studio (sln)”选项而不是“MSBuild”。 如果重要的话,我们使用 Subversion 进行源代码控制。 我们的 TeamCity 版本是 6.5.1(内部版本 17834)。
Right now our assemblies have a version number like 2.0.831.0. As I understand it, that's major version, minor version, date and build number. If I make a change and build again on the same day it's 2.0.831.1, 2.0.831.2 etc.
My TeamCity build number format is simply 2.{0} where {0} is an auto incremented number that just goes on forever (2.195, 2.196 etc).
How do I make TeamCity look exactly like the assembly version? We want to be able to associate the Change Log with the assembly version so anyone can say assembly version 2.0.831.2 had these changes in these files.
Extra info:
Our build step uses the "Visual Studio (sln)" option instead of "MSBuild" if that matters.
We use Subversion for source control if that matters.
Our TeamCity version is 6.5.1 (build 17834).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您采用语义版本控制方案
{major}.{minor}.{patch} 并为版本号附加第四个元素
{major}.{minor}.{patch}.{build}
。这对于将构建日期包含到版本控制方案中更有用。
TeamCity 6.5(您尚未指定版本)具有构建功能,可用于在构建过程中修补 AssemblyInfo.cs 中的版本。请参阅 AssemblyInfo Patcher 的文档。
然后,您可以按照您希望在程序集中使用的方式定义内部版本号格式并使用构建本身的格式以及修补功能。
I would recommend you to adopt the semantic versioning scheme
{major}.{minor}.{patch}
and append a 4th element for the build number{major}.{minor}.{patch}.{build}
.This is way more useful as to include the build date into the versioning scheme.
TeamCity 6.5 (you haven't specified a version) has a build feature which could be used to patch the version in the AssemblyInfo.cs during the build. See the documentation for the AssemblyInfo Patcher.
You could then define the build number format in the way you would like to have in your assembly and use the format for the build itself, as also for the patching feature.
一种解决方案是使用 MSBuild 运行程序,并编写一个 MSBuild 脚本,该脚本从 AssemblyInfo 文件中读取版本信息,在运行构建时将 TeamCity 构建版本设置为该值,然后递增该版本的构建号部分,并写入值返回到 AssemblyInfo。
这并不是特别简单,因为您需要了解编写自定义 MSBuild 脚本,并且您可能需要使用一些社区任务等来读取/写入版本信息。
我们还使用全局 AssemblyInfo 文件的概念,我们的所有程序集都会引用该文件(使用 VS 中的“添加链接”),因此我们只需要在构建过程中更新一个文件。
这里有一篇很棒的文章,其中描述了使用 MSBuild 执行常见的 CI 任务。他正在使用 CruiseControl.NET,但其中大部分内容仍然适用。如果您运行的是 TeamCity 6.5,我会考虑专门使用其构建功能,因为这比自定义 MSBuild 脚本更容易维护。
One solution is to use the MSBuild runner, and write an MSBuild script which reads the version information from the AssemblyInfo file, sets the TeamCity build version to that value whilst running the build, then increments the build number part of that version, and writes the value back to the AssemblyInfo.
This isn't particularly trivial, as you need to have an understanding of writing custom MSBuild scripts, and you will likely need to use some of the community tasks etc to read/write the version information.
We also use the concept of a global AssemblyInfo file, which all of our assemblies reference (using Add Link in VS), and thus we only need to update the one file during the build.
There is an excellent article here, which describes doing common CI tasks with MSBuild. He is using CruiseControl.NET, but much of it still applies. If you are running TeamCity 6.5 though, I would look into using its build features exclusively, as this will be much easier to maintain than a custom MSBuild script.