In TFS Build 2008 you could generate custom build numbers by overriding the BuildNumberOverrideTarget and setting a property called BuildNumber. What does this look like in TFS Build 2010? The default build numbers are generated by the Update Build Number activity towards the beginning of the workflow as shown here:
The default activity generates build numbers based on the Build Number Format specified on the Process tab of the Build Definition dialog:
So how do we replace this with our own custom build number generation scheme? We simply remove the existing activity from the workflow and replace it with one of our own.
Getting Started
Removing The Existing Build Number Generation Scheme
Creating A New Build Number Generation Scheme
[BuildActivity(HostEnvironmentOption.Controller)]
protected override void CacheMetadata(CodeActivityMetadata metadata)
{
base.CacheMetadata(metadata);
metadata.RequireExtension(typeof(IBuildDetail));
protected override void Execute(CodeActivityContext context)
Random randomGenerator = new Random();
int buildNumber = randomGenerator.Next();
var buildDetail = context.GetExtension<IBuildDetail>();
buildDetail.BuildNumber = String.Format("{0}_{1}", buildDetail.BuildDefinition.Name, buildNumber);
buildDetail.Save();