Versioning Code in TFS – Part 2


7 Nov 2009: Update

In Versioning Code in TFS – Part 1 I covered most of my thoughts on the matter. I’ve since helped a colleague out with implementing code versioning using GetBuildNumber and SetBuildNumber in the FTDTFSBuild task. I was disappointed that the experience wasn’t as smooth as it could have been and following a few discussions, a few changes have been made to the FTDTFSBuild Task to improve the functionality and user experience. These have all shipped in the latest beta release of the FreeToDev MSBuild Tasks Suite.

Summary of Changes
Name changes to alleviate confusion:
  • FTDTFSBuild —> FTDTFSVersion
  • GetBuildNumber —> GetVersion
  • SetBuildNumber —> SetVersion
  • BuildType —> BuildName
  • BuildNumber & CalculatedBuildNumber —> Version
  • Encoding —> TextEncoding to be consistent with other tasks
  • Format —> VersionFormat
  • VersionFormat Date option —> DateTime
Enhancements
  • ZeroPadding has been split into PaddingCount and PaddingDigit
  • Padding is now supported for VersionFormat=”DateTime”, not just VersionFormat=”Elapsed”
  • TextEncoding is now optional. Defaults to UTF8
  • If a file is made write-able, it is now set back to read-only after versioning
Updated Sample

    <!– 1. Import the Tasks–>
    <Import Project=”C:\Program Files\FreeToDev\MSBuild Tasks Suite 3.5\FreeToDev.MSBuild.tasks”/>
    <ItemGroup>
        <!– 2. Create an Item Collection of files to version –>
        <FilesToVersion Include=”C:\POC\AssemblyInfo.cs”/>
    </ItemGroup>
    <!– Team Build Code omitted for brevity –>
    <Target Name=”BuildNumberOverrideTarget” Condition=”‘$(IsDesktopBuild)’!=’true'”>
        <!– 3a. Get the version using the current Team Build properties. This example uses the Elapsed VersionFormat. Note, if you are using TFS2005, then use $(BuiltType) rather than $(BuildDefinition) for the BuildName property–>
        <FTDTFSVersion TaskAction=”GetVersion” BuildName=”$(BuildDefinition)” TFSBuildNumber=”$(BuildNumber)” VersionFormat=”Elapsed” StartDate=”1 Jan 2000″ PaddingCount=”4″ PaddingDigit=”1″ Major=”3″ Minor=”5″>
            <Output TaskParameter=”Version” PropertyName=”NewVersion”/>
        </FTDTFSVersion>
        <Message Text=”Elapsed Version is $(NewVersion)”/>
        <!– 3b. This example uses the DateTime VersionFormat. Note, if you are using TFS2005, then use $(BuiltType) rather than $(BuildDefinition) for the BuildName property–>
        <FTDTFSVersion TaskAction=”GetVersion” BuildName=”$(BuildDefinition)” TFSBuildNumber=”$(BuildNumber)” VersionFormat=”DateTime” DateFormat=”MMdd” PaddingCount=”5″ PaddingDigit=”1″ Major=”3″ Minor=”5″>
            <Output TaskParameter=”Version” PropertyName=”NewVersion”/>
        </FTDTFSVersion>
        <Message Text=”Date Version is $(NewVersion)”/>
    </Target>
    <Target Name=”AfterGet” Condition=”‘$(IsDesktopBuild)’!=’true'”>
        <!– 4. Set the version in the file collection –>
        <FTDTFSVersion TaskAction=”SetVersion” Files=”%(FilesToVersion.Identity)” Version=”$(NewVersion)”/>
    </Target>

Advertisements

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 )

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