First time here? You are looking at the most recent posts. You may also want to check out older archives or the tag cloud. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS. Thank you for visiting! (hide this)

In the last month I started working again a lot on CruiseControl and build processes.

Another quick tip I think it's interesting to share is how to have the version number of the code you are building synchronized with the build number generated by CruiseControl.NET.

As everything related to build processes inside CC.NET this is achieved using a NAnt task: asminfo.

Step 1 - CC.NET Labeler

The first thing you have to setup is the labeler inside the ccnet.config file:

<labeller type="defaultlabeller">
  <prefix>2.2.0.</prefix>
  <incrementOnFailure>False</incrementOnFailure>
</labeller>

This will instruct CC.NET to prefix the build label with the major.minor.revision of your product.

Step 2 - Setup solution AsseblyInfo.cs file

Next step is to add a VersionInfo.Designer.cs as solution file and link it in all the project of your solution: now you will have the same version in all the assembly produced by the build.

using System;
using System.Reflection;

[assembly: AssemblyVersionAttribute("2.2.0.0")]

This file will be overridden on the build server with the right version number, but when developer compile on their local machine, then the build number will always be 0, so it will be easy to identify "official" builds from the local ones.

Step 3 - NAnt build script

Last step, add the following task inside the NAnt build script

<asminfo output="VersionInfo.Designer.cs" language="CSharp">
    <imports>
        <import namespace="System" />
        <import namespace="System.Reflection" />
    </imports>
    <attributes>
        <attribute type="AssemblyVersionAttribute" value="${CCNetLabel}" />
    </attributes>
</asminfo>

posted on Friday, February 23, 2007 5:31 PM

Comments on this entry:

# re: Synchronize assembly version with CC.NET build number with NAnt

Left by Alex Henderson at 2/23/2007 6:09 PM

I'm always torn between labeling assemblies with the build number from CC.Net and Revision number from the SCM (Subversion in my case) - do you tag your SCM with the build label as well?

# re: Synchronize assembly version with CC.NET build number with NAnt

Left by Simone Chiaretta at 2/23/2007 9:34 PM

I prefer having CC.NET generate the build number and than label the SCM with that label, since SVN revision number doesn't depend just on the project, but all the branch in the source repository.
In some project I label the SCM back, in other I don't...

# re: Synchronize assembly version with CC.NET build number with NAnt

Left by Laboremus at 5/5/2007 1:29 PM

Isn't the Labeller reset every time the CC.NET server is restarted? I don't know if there is a way to start it from some particular point.
In my build I create tag every time with copy of the trunk and cimpiled binaries. There is a posibility then that my tags will collide.
To the Alex point - the SVN revision number can be quite big - more than 9999, while version.revision should be 4 digits if am not worng... What I thought could be useful is tag the build back to the SVN and name it after version and revision - this way we kind of map them together.

# re: Synchronize assembly version with CC.NET build number with NAnt

Left by Simone Chiaretta at 5/5/2007 2:35 PM

No, the label is kept on a state file stored on the disk, so you don't loose the label when you restart the server.

# re: Synchronize assembly version with CC.NET build number with NAnt

Left by Laboremus at 5/13/2007 2:37 AM

There is another solution to the version control - through the separate file http://lazyloading.blogspot.com/2007/05/updating-assembly-version-with-ci.html
I know that labeller can share the the state files between the separate projects but that one seems simpler...

Comments have been closed on this topic.