Custom Build Number In Team Build
Software Development, Team System December 13th, 2007
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.
Tags: MSBuild
About




