MSBuild TFS Build Number

17,056

Assuming you mean Team Build, the $(BuildNumber) property contains the current build number.

See http://blogs.msdn.com/aaronhallberg/archive/2008/02/12/team-build-2008-property-reference.aspx for a full reference of available properties.

If you're just running MSBuild, I don't believe it generates/applies an overall build number (each project will have an individual, possibly auto-incremented, version number in its AssemblyInfo.cs [by default] file). You can dynamically get this version number for a specific assembly using the System.Reflection.Assembly class at runtime.


Update

As of TFS 2010, the 'BuildNumber' variable is no longer automatically passed to the MSBuild process by TFS. TFS 2010 now uses Windows Workflow as its internal build engine, so if you want the build number, you'll have to modify your build definition to include it, as mentioned in this MSDN article.

Share:
17,056

Related videos on Youtube

minalg
Author by

minalg

Updated on June 04, 2022

Comments

  • minalg
    minalg almost 2 years

    I have been using SVN for a little while now. recently on a project I am using TFS. With the builds I like to append/update the build version number on the project output. I do this on the masterpage so that it is clearly visible on the application. Since the application could be running on multiple machines, it is handy information on which verison are running.

    I achive this in SVN world as:

      <!-- Import of the MSBuildCommunityTask targets -->
        <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
        <!-- to AssemblyInfo to include svn revision number -->
        <Target Name="BeforeBuild">
          <SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="$(ProgramFiles)\CollabNet Subversion Client">
            <Output TaskParameter="Revision" PropertyName="Revision" />
          </SvnVersion>
          <Time>
            <Output TaskParameter="Year" PropertyName="Year" />
            <Output TaskParameter="Month" PropertyName="Month" />
            <Output TaskParameter="Day" PropertyName="Day" />
          </Time>
          <FileUpdate Files="MasterPage.master" Regex="svn revision: (\d+)\.(\d+)\.(\d+)\.(\d+)" ReplacementText="svn revision: $(Year).$(Month).$(Day).$(Revision)" />
        </Target>
    

    As you can see above the "BeforeBuild" task updates the masterPage.master file with the YYYY.MM.DD.SVNVERSION stamp.

    How can I achive this with TFS as the source control. How do I get the TFS build number?

  • minalg
    minalg over 14 years
    Thanks, solved it. <TfsVersion LocalPath="$(MSBuildProjectDirectory)"> <Output TaskParameter="Changeset" PropertyName="Revision"/> </TfsVersion>
  • technophile
    technophile over 14 years
    Ah, yes, that's a good solution for non-team build builds, I'll have to remember that.
  • berhir
    berhir almost 10 years
    At least since TFS 2013 you don't have to modify the build definition. You can read the environment variable $(TF_BUILD_BUILDNUMBER). For a list of all environment variables see this answer: stackoverflow.com/questions/22293671/…