Setting AssemblyVersion number in TeamCity 6.5

You know the process where you need to increment the AssemblyVersion for each build? Personally I’ve solved it both using MSBuild and PowerShell as a part of our daily builds. We have also touched on the subject of incrementing version numbers in earlier posts, like:

But the fact is, at least for Visual Studio projects, this can be done in two steps without writing any code at all. Simply put, it just got really easy. To accomplish this we’ll be using TeamCity’s Addition Build Features.

Step 1 – Set a build number format

I used the format 0.1.0.{0} (where {0} will be replaced by the build counter), but you can basically put anything you like here.

buildnumber

The build number format will automatically be stored in TeamCity as %build.number% which we will use in the next step.

Step 2 – Add an additional build step

When configuring your Build Steps you can also add something called Additional Build Features. One of those features is called AssemblyInfo patcher and it’s described like this.

AssemblyInfo Patcher build feature allows to set a build number to an assembly automatically, without having to patch AssemblyInfo.cs files manually. When adding this build feature you need only to specify version format. Note, that you can use TeamCity parameter references here.

So just add this feature and put your %build.number% as the assembly version format.

build feature

Done and done. For every build TeamCity will now update AssemblyInfo.cs, build your solution and then revert the changes that it made to the file. So we’ll end up with an assembly with a version number and unchanged source files.

Maintainable, clean and simple.

This Post Has 2 Comments

  1. The issue I found with this, my build does a ClickOnce publish on one *.csproj file, and it does not update the assembly.info files for the other DLL projects being referenced by the one I’m publishing. A little dismayed by that.

  2. Bummer. :-/
    Well, you can always run this PowerShell script as a first build step.

    (Get-childitem -include AssemblyInfo.cs -recurse) | Foreach-Object { Set-Content $_ ((Get-content $_) -replace “(d.d.d).d*”, “%build.number%”)}

    Should solve your problem.

Leave a Reply

Close Menu