Click here to Skip to main content
13,861,459 members
Click here to Skip to main content
Add your own
alternative version


1 bookmarked
Posted 12 Feb 2011
Licenced CPOL

Customize the Build Number in Team Build

, 12 Feb 2011
Rate this:
Please Sign up or sign in to vote.
Customize the Build Number in Team Build

If you have used TFS team build, you know that MSBuild creates a default label and build number/name with the following format:

Build Definition Name_YYYYMMDD_#

Where the # is an incremental number for the date. This format does not really provide any information about the version your are building. Nevertheless, the build number can be customized using the BuildNumberOverrideTarget. There are different approaches to achieve this. In this instance, we will take a very simple approach that will allow us to add the current product version to the build number without having to use a custom task which requires the deployment of a assembly on the build machine. The one item to always keep in mind is that the build number must be unique.

Open your TFs build project and add the following property group:


We just added a group of variables that indicate that the product we want to build has this version You can change this to match your standard and your product version. Now add the target override as follows:

<Target Name="BuildNumberOverrideTarget">
    <Message Text="Build number before [$(BuildNumber)]" />
    <Message Text="Build number after [$(BuildNumber)]" />

With this override, we are basically indicating that we want to append our version number to the TFS build number. We decided to keep the TFS build number to continue to provide a unique label/number to the build. The messages in the override log the build number before and after the change. If you check in your changes and queue a build, you will see that the build number has changed to this new format:


You will now be able to easily see the version associated to the build. When you are ready to build a new version, you will need to modify the property group. You should also know that if you try to build during the same day, you will probably get a non-unique build number error. This is because the build number that was generated was replaced by our custom build number, and the build process uses the "Build Definition Name_YYYYMMDD_#+1" to increment the build for the same date. To address this, you can add a parameter and append it to the build number as follows:

The build label parameter should be added to the MSBuild command-line arguments as follows:


The custom build task should address this limitation, but this is part of a different blog entry.

I hope this is helpful.

<Target Name="BuildNumberOverrideTarget">
    <Message Text="Build number before [$(BuildNumber)]" />
    <Message Text="Build number after [$(BuildNumber)]" />


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Architect OG-BITechnologies
United States United States
Software engineer, author & speaker who enjoys mentoring, learning, speaking and sharing with others about software development technologies. Microsoft MVP.

My Blog

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190214.1 | Last Updated 13 Feb 2011
Article Copyright 2011 by ozkary
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid