Custom Build Number In Team Build

Many users want to modify the default build number of Team System Team Build which looks like: <Build-Type-Name>_<Date>.XXX.

You can change it by writing a custom task and call it in the BuildNumberOverrideTarget target of the MSBuild file. In this example the task will generate a unique build number based on current time:

using System;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;


namespace MaorDavidBlog.Samples.MSBuild
{
public class BuildNameGenerator:Task
{

private string _buildName;

public override bool Execute()

{
_buildName = DateTime.UtcNow.ToString();
return true;
}



[Output]
public string BuildName

{
get { return _buildName; }
}

}
}

The attribute “Output” indicates that BuildName property is output of the custom task.

Then, register the task in TFSBuild.proj file.

<!-- Add using task line just after import statement - - >
<UsingTask
TaskName="MaorDavidBlog.Samples.MSBuild.BuildNameGenerator"
AssemblyFile="$(MyCustomTasks)MaorDavidBlog.Samples.MSBuild.dll"/>



<! -- Override the target towards the end of proj file - - >
<Target Name = "BuildNumberOverrideTarget" >
<BuildNameGenerator>
<Output TaskParameter="BuildName"
PropertyName="BuildName"/>
</BuildNameGenerator>
</Target>

 

Next time you’ll execute your build, you’ll see your custom build name.

Advertisements

2 Responses to Custom Build Number In Team Build

  1. maord says:

    This comment originally written by:Many users want to modify the default build number of Team System Team Build which looks like: <Build-Type-Name>_<Date>.XXX. You can change it by writing a custom task and call it in the BuildNumberOverrideTarget target of the MSBuild file

  2. maord says:

    This comment originally written by:Team System NewsMaor David on Custom Build Numbers in Team Build. GertD on Cleaning up DesignDB Leftovers and Is DesignDB…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: