TFS Build Number Tasks

UPDATE: 13 July 08 — These tasks are now available in the FreeToDev MSBuild Tasks Suite

UPDATE (15 May08): See this post for TFS 2008 support

I’ve added two simple tasks to the FreeToDev.MSBuild.Tasks assembly, both relate to build numbers in TFS. I’ve previously modified and used the AssemblyInfo task to get assembly versions consistent across all assemblies produced by a team build. I have a few pet hates with regard to this task though.

  1. It’s very easy to get into ‘unable to determine the workspace’ hell
  2. You typically have to change the code to suite your build number format
  3. It updates the assemblyinfo files in source control
  4. It crashes if any files it processes do not contain versioning attributes.

The following tasks are intended to provide a lightweight and flexible solution to getting your assemblies versioned consistently in a team build.

 

  • GetBuildNumber – This can be used in two ways. It will base the build part on either the number of days that have elapsed since a given date or on a date format, eg.

<GetBuildNumber BuildType="$(BuildType)" BuildNumber="$(BuildNumber)" Format="Elapsed" StartDate="1 Jan 2007" ZeroPadding="4" Major="2" Minor="1">
        <Output TaskParameter="AssemblyFileVersion" PropertyName="ElapsedBuildNo" />
</GetBuildNumber>
<GetBuildNumber BuildType="$(BuildType)" BuildNumber="$(BuildNumber)" Format="Date" DateFormat="MMdd" Major="2" Minor="1">
        <Output TaskParameter="AssemblyFileVersion" PropertyName="DateBuildNo" />
</GetBuildNumber>

 

  • SetBuildNumber – this is used to set the build number in a given collection of files.

Team Build Sample

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="DesktopBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\TeamBuild\Microsoft.TeamFoundation.Build.targets"/>
    <Import Project="FreeToDev.MSBuildTasks.tasks"/>
    <ItemGroup>
        <FilesToVersion Include="C:\POC\AssemblyInfo.cs"/>
    </ItemGroup>
    <!– Team Build Code omitted for brevity –>
    <Target Name="BuildNumberOverrideTarget" Condition="’$(IsDesktopBuild)’!=’true’">
        <ShowBuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildURI="$(BuildUri)" BuildStep="TARGET OVERRIDE: BuildNumberOverrideTarget"/>
        <GetBuildNumber BuildType="$(BuildType)" BuildNumber="$(BuildNumber)" Format="Elapsed" StartDate="1 Jan 2007" ZeroPadding="4" Major="2" Minor="1">
            <Output TaskParameter="AssemblyFileVersion" PropertyName="ElapsedBuildNo"/>
        </GetBuildNumber>

        <OnError ExecuteTargets="OnError"/>
    </Target>
    <Target Name="AfterGet" Condition="’$(IsDesktopBuild)’!=’true’">
        <ShowBuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildURI="$(BuildUri)" BuildStep="TARGET OVERRIDE: AfterGet"/>
        <SetBuildNumber Files="%(FilesToVersion.Identity)" BuildNumber="$(ElapsedBuildNo)" Encoding="UTF8"/>
        <!– add any addition processing required –>
        <OnError ExecuteTargets="OnError"/>
    </Target>
    <!– Team Build Code omitted for brevity –>
</Project>

Download the latest version with samples here….FTD

Advertisements
This entry was posted in Team Foundation Server. Bookmark the permalink.

39 Responses to TFS Build Number Tasks

  1. Kevin says:

    I like the simplified task for setting version numbers for assemblies, but it would be great if updating the AssemblyVersion attribute was supported as well.  Any plans?
     
    Kevin

  2. Mike says:

    I didn\’t have any plans for that. Easy enough to do, however why would you change the assembly version with each build?

  3. Unknown says:

    I\’d like the assembly version attribute updated too. Why wouldn\’t you?

  4. Mike says:

    See this update for the ability to set the AssemblyVersion

  5. Marais says:

    Sorry for asking a stupid question… In the SDC.Tasks library there is a versioning task, apart from the fact that your versioning task is using dates and the SDC task library\’s task is using autoincrimenting values, what are the differences between the tasks?
     
    I have been using the SDC task versioning for some time now and it works wonder for me, just would like you oppinion…
     
    Thanks,
     
    Marais

  6. Mike says:

    If you have a solution that is working for you, then I would suggest you stick with it. Please take a read of this post: http://freetodev.spaces.live.com/blog/cns!EC3C8F2028D842D5!404.entry and let me know if you have any further thoughts.Regards… FTD

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s