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.

Similar Posts:

Tags:



2 Comments to “Custom Build Number In Team Build”

  1. maord | June 22nd, 2009 at 23:09

    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 | June 22nd, 2009 at 23:09

    This comment originally written by:Team System News

    Maor David on Custom Build Numbers in Team Build. GertD on Cleaning up DesignDB Leftovers and Is DesignDB…

Leave a Comment