Condividi tramite


Team Build and the AssemblyInfo Task

Gautam Goenka, dev lead for Team Build v1, wrote a blog post way back in January of 2004 that laid out an approach for using the AssemblyInfo task to update version numbers with Team Build.  I refer people to this post all the time, and have never had anyone report any issues with the post...  As such, I never really looked at it too closely, and didn't really understand how it worked. 

Earlier this week, however, a customer was running into some trouble here and I figured the time had finally come for me to dig a bit deeper. 

The idea with the AssemblyInfo task is to (a) import Microsoft.VersionNumber.targets, (b) populate the AssemblyInfoFiles item group with the list of AssemblyInfo.* files to be updated, and (c) set whatever properties you want to modify - AssemblyMajorVersion, AssemblyMinorVersion, etc.  Internally, this all works due to the following bit of markup in Microsoft.VersionNumber.targets:

 <!-- Re-define CoreCompileDependsOn to ensure the assemblyinfo files are updated before compilation. -->
<PropertyGroup>
  <CoreCompileDependsOn>
    $(CoreCompileDependsOn);
    UpdateAssemblyInfoFiles
  </CoreCompileDependsOn>
</PropertyGroup>

This adds the UpdateAssemblyInfoFiles target, which executes the AssemblyInfo task, to the dependencies of the CoreCompile target.  By convention, each of the various project types built by MSBuild declare their CoreCompile targets as follows:

   <Target Name="CoreCompile" DependsOnTargets="$(CoreCompileDependsOn)">

This is true of Microsoft.CSharp.targets, Microsoft.VisualBasic.targets, etc.  Crucially, it is also true of Microsoft.TeamFoundation.Build.targets, which defines the Team Build build process.

So - if you want to use the AssemblyInfo task to update the version numbers for an individual C# project, you can follow the above steps in your *.csproj file.  In this case, the individual C# project's AssemblyInfo.cs file would get updated just before the project was compiled.

If, on the other hand, you want to update the version numbers for all of the projects built during your Team Build build, you can follow the above steps in your TfsBuild.proj file, as laid out in Gautam's blog post.  In this case, all of the AssemblyInfo.* files included in the AssemblyInfoFiles item group would get updated just before Team Build starts the compilation of all of the solutions in the SolutionToBuild item group.

Comments

  • Anonymous
    June 09, 2007
    The comment has been removed
  • Anonymous
    June 12, 2007
    The comment has been removed
  • Anonymous
    July 03, 2007
    The AssemblyInfo task has a new home, because the CodeGallery portion of GoDotNet is being phased out.
  • Anonymous
    July 03, 2007
    The AssemblyInfo task has a new home, because the CodeGallery portion of GoDotNet is being phased out
  • Anonymous
    July 19, 2007
    The comment has been removed
  • Anonymous
    February 17, 2009
    For error: Skipping target "UpdateAssemblyInfoFiles" because all output files are up-to-date with respect to the input files.I found that it does this error when solution has only one project!Can anybody tells why this happens?
  • Anonymous
    January 16, 2011
    Hi,I tried above steps, its working fine in local machine. But if I tried build from server using Default Template build definition, its not increament the revision type.Default Template, each time clean workspace and build it. So its automatically revision number is zero.I'm using TFS2010/Please help me to resolve this problem
  • Anonymous
    January 28, 2011
    I would love to see an answer for this as well Rajesh. I can't get this to work at all in TFS 2010.