Mike's profileFreeToDevBlogLists Tools Help

Blog


    July 24

    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>


    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.
    Mike Fourie has turned off comments on this page.

    Trackbacks (1)

    The trackback URL for this entry is:
    http://freetodev.spaces.live.com/blog/cns!ec3c8f2028d842d5!547.trak
    Weblogs that reference this entry