6

We have a C# solution with a WiX installer and an MSBuild build script. We're in the process of migrating from SVN to 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. The MSBuild script defines a ProductVersion property, which included the SVN revision number as the final of the four numbers of the build version. However, we can't use that anymore, as we won't be using SVN anymore.

I've been trying to find a replacement for the SVN revision number, but I can't figure out what to use.

  • Jenkins provides a build number that I could use, but I don't want to tie our versioning system to 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.

  • We can set the AssemblyVersion to 1.0.* and let .NET fill in the rest. This works for our assemblies, but I can't find a way to inject this into 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.

  • 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. 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?

jqno
  • 15,133
  • 7
  • 57
  • 84

3 Answers3

7

The MSbuild Community Tasks contains a task named Version, it provides some algorithms to generate version numbers. 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. I would recommend using jenkins build number, as Christopher Painter did.

Marcos Brigante
  • 974
  • 9
  • 25
  • I see that BuildType="Automatic" and RevisionType="Automatic" do the same thing as * in the AssemblyVersion. Nice! That solves it for me. – jqno Jan 16 '13 at 12:48
1

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.

Then just let .NET generate the Assembly numbers and WiX will use it as the ProductVersion.

ChrisPatrick
  • 984
  • 7
  • 19
  • That's the catch-22 I was referring to: which assembly do I use? I'd have to build it first... – jqno Jan 15 '13 at 18:41
  • I mean I could do that, but I'd have to separate the build into 2 separate steps, while now its one clean and simple call that builds the entire solution. – jqno Jan 15 '13 at 18:49
  • This is exactly how I do it and I don't have to run MSBuild in 2 steps. As the Wix installer will reference the .NET assembly/executable it will wait until that is built before using reading the version. I generally use the main entry point of the application as the file to bind to. – caveman_dick Jan 16 '13 at 10:04
  • Exactly. Surely the build has to wait until the assemblies are built until it can build the installer anyway? Otherwise how could it package up those assemblies into the installer? – ChrisPatrick Jan 16 '13 at 10:46
  • Hm, yeah, now that I read this back, it indeeds sounds a bit silly, sorry about that :). But still, we actually have multiple projects in the same solution, with each their own WiX installer. And since I don't want to take on the Big Wix Refactoring in the middle of a migration to git, it'd mean doing this in 6 separate WiX scripts, where previously, the version was just passed in... – jqno Jan 16 '13 at 12:42
1

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. That's how I've done it with BuildForge, TFS et al.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • I want to have the possibility to make a build by hand from the command-line as well, and not get into versioning issues. – jqno Jan 16 '13 at 12:47
  • 4
    I usually do something like 0.0.0.1. This way if I run the MSBuild by hand it defaults to 0.0.0.1 but if my real build automation (TFS, BuildForge, Jenkins et al ) runs it I can pass /p:ProductVersion=1.2.3.4 and have it override it. – Christopher Painter Jan 16 '13 at 13:11