简体   繁体   English

在MSBuild中生成版本号

[英]Generating version number in MSBuild

We have a C# solution with a WiX installer and an MSBuild build script. 我们有一个带有WiX安装程序和MSBuild构建脚本的C#解决方案。 We're in the process of migrating from SVN to Git. 我们正在从SVN迁移到Git。

As the fourth part of our version number, we want something that ascends with each build. 作为我们版本号的第四部分,我们希望每个构建都能提升。 Until now, we've used the SVN revision number for that. 到目前为止,我们已经使用了SVN版本号。 The MSBuild script defines a ProductVersion property, which included the SVN revision number as the final of the four numbers of the build version. MSBuild脚本定义了一个ProductVersion属性,其中包含SVN修订版号作为构建版本的四个数字的最后一个。 However, we can't use that anymore, as we won't be using SVN anymore. 但是,我们不能再使用它,因为我们将不再使用SVN。

I've been trying to find a replacement for the SVN revision number, but I can't figure out what to use. 我一直试图找到SVN版本号的替代品,但我无法弄清楚要使用什么。

  • Jenkins provides a build number that I could use, but I don't want to tie our versioning system to Jenkins. Jenkins提供了我可以使用的内部版本号,但我不想将我们的版本控制系统与Jenkins联系起来。

  • Jenkins also provides a timestamp, but it doesn't comply with Microsoft's version number restrictions: it's alphanumeric and kind of long, while the 4th number in the version should be an integer between 0 and 65535. Jenkins还提供了时间戳,但它不符合Microsoft的版本号限制:它是字母数字且有点长,而版本中的第4个数字应该是0到65535之间的整数。

  • We can set the AssemblyVersion to 1.0.* and let .NET fill in the rest. 我们可以将AssemblyVersion设置为1.0。*并让.NET填写其余部分。 This works for our assemblies, but I can't find a way to inject this into WiX. 这适用于我们的程序集,但我找不到将其注入WiX的方法。 We can fetch it from one of the assemblies once it's built, but our MSBuild script uses the <MSBuild> task to build the whole solution at once, so we're stuck in a Catch-22 where we need to run <MSBuild> so it can compile an assembly that we can use to fetch the generated version number, but in order to run <MSBuild> , we first need to have a compiled assembly so that we can fetch the generated version number from it. 我们可以在构建之后从其中一个程序集中获取它,但我们的MSBuild脚本使用<MSBuild>任务一次构建整个解决方案,因此我们陷入了Catch-22,我们需要运行<MSBuild>所以它可以编译我们可以用来获取生成的版本号的程序集,但是为了运行<MSBuild> ,我们首先需要一个已编译的程序集,以便我们可以从中获取生成的版本号。

  • I could add a separate Target in the MSBuild file that compiles something (anything) and get the version number from that, and then do the actual call to the <MSBuild> task. 我可以在MSBuild文件中添加一个单独的Target来编译某些东西(任何东西)并从中获取版本号,然后执行对<MSBuild>任务的实际调用。 But that just feels wrong. 但那只是感觉不对。

Again, I don't really care what the number is, as long as it increments with every build. 同样,我并不关心数字是什么,只要它随着每次构建而增加。 Something based on a timestamp would be fine. 基于时间戳的东西会很好。 Any ideas? 有任何想法吗?

The MSbuild Community Tasks contains a task named Version , it provides some algorithms to generate version numbers. MSbuild社区任务包含一个名为Version的任务,它提供了一些生成版本号的算法。 It is very easy to use and customizable. 它非常易于使用和定制。

IMHO, it is better to use a number that ties your entire SDLC, so you can trace your deployed product to the build results, and these to the VCS, and so forth. 恕我直言,最好使用一个绑定整个SDLC的数字,这样您就可以将已部署的产品跟踪到构建结果,将这些产品跟踪到VCS,依此类推。 I would recommend using jenkins build number, as Christopher Painter did. 我建议使用jenkins内部编号,正如Christopher Painter所做的那样。

You can get the version number from an assembly by using !(bind.FileVersion.FileId) where FileId is the ID of a File element as defined in one of your wxs files. 您可以使用!(bind.FileVersion.FileId)从程序!(bind.FileVersion.FileId)获取版本号,其中FileId是您在其中一个wxs文件中定义的File元素的ID。

Then just let .NET generate the Assembly numbers and WiX will use it as the ProductVersion. 然后让.NET生成程序集编号,WiX将其用作ProductVersion。

Why wouldn't you tie it to Jenkins? 你为什么不把它绑在詹金斯身上? Seems like you'd want Jenkins to manager the properties that get passed into a build including version number. 好像你希望Jenkins管理传递给包含版本号的构建的属性。 That's how I've done it with BuildForge, TFS et al. 这就是我用BuildForge,TFS等人做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM