4
votes

I have done a lot of googling but cant seem to find an exact solution to get the TeamCity build number into my AssemblyInfo files. Would appreciate a full solution for my requirements...

1 Get the build number into a Nant variable. I believe that this code will accomplish this..

   PropertyGroup

      Version$(BUILD_NUMBER)/Version

/PropertyGroup 

(repoduced as best as possible in SO).

2 Now I need a way to update the revision component of my version numbers so I get something like 1.0.0.[build number].

3 Ideally I need the whole thing in a re-usable Nant target so that I can just call it passing in the path to the assembly info file that i want to update.

I would respectfully request that if you can help me that a full solution is posted here with explanation as opposed to links to other sites. Ive looked at a lot of online examples but cant seem to find one that fits what I need - therefore I request the knowledge of the omnipotent SO community!

Thanks in advance.

2

2 Answers

3
votes

First of all, the code snippet in your question is MSBuild syntax, not NAnt. Assuming that NAnt is your build tool, there is a good explanation of how to update AssemblyInfo files with Cruise Control.NET here. That applies to TeamCity as well, just replace "CCNetLabel" with "build.number" and you will be fine.

To get a version number like 1.0.0.[build number], you can accomplish that in the TeamCity build configuration. On the first configuration page (General Settings). Change the "Build Number Format" from "{0}" to "1.0.0.{0}". See the online help for more options.

2
votes

I know you asked for an NAnt reusable task, but this is too cool.

TeamCity has a new feature tailor-made for this purpose (AssemblyInfo Patcher). You don't have to change anything in the (NAnt) build. Just add the "Additional Build Feature" for AssemblyInfo patcher in the Build Steps configuration for the build. You can also set the format for the version there.