Using AssemblyInfo task with Team Build

Fixed a bug in the snippet as pointed out by Peter from Microsoft Consulting Service. I was earlier using ItemGroup to get all AssemblyInfoFiles which gets executed before any target (and hence before Get task). So, the items in AssemblyInfoFiles may be outdated. The right approach is to use CreateItem task inside AfterGet target.

Neil Enns of MSBuild team has put up a task to automatically update assembly info (like assembly version) of Visual Studio projects as part build process here.

The task can easily be extended to work with Team Build. The sample TFSBuild.proj file that works is below.  The changes made by me are underlined.

Note –

  1. The import statement should come second.
  2. I installed AssemblyInfoTask in GAC.  If you have installed it in Application Data folder, you will need to change the import statement accordingly.
  3. This assumes that you are changing all AssemblyInfo.cs files to same version.  If that is not the case, have multiple AssemblyInfoSpec property and repeat the tasks for each property.



<?xml version=“1.0” encoding=“utf-8”?>
<Project DefaultTargets=“DesktopBuild”

To edit the build type, you will need to edit this file which was generated
by the Create New Build Type wizard. This file is under source control and
needs to be checked out before making any changes.

The file is available at –
where you will need to replace TeamProjectName and BuildTypeName with your
Team Project and Build Type name that you created

Checkout the file
1. Open Source Control Explorer by selecting View -> Other Windows -> Source Control Explorer
2. Ensure that your current workspace has a mapping for the $/{TeamProjectName}/TeamBuildTypes folder and
that you have done a “Get Latest Version” on that folder
3. Browse through the folders to {TeamProjectName}->TeamBuildTypes->{BuildTypeName} folder
4. From the list of files available in this folder, right click on TfsBuild.Proj. Select ‘Check Out For Edit…’

Make the required changes to the file and save

Checkin the file
1. Right click on the TfsBuild.Proj file selected in Step 3 above and select ‘Checkin Pending Changes’
2. Use the pending checkin dialog to save your changes to the source control

Once the file is checked in with the modifications, all future builds using
this build type will use the modified settings
<!— Do not edit this —>
<Import Project=“$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\TeamBuild\Microsoft.TeamFoundation.Build.targets” />
<Import Project=“$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.Targets”/>
The description is associated with a build type. Edit the value for making changes.
Name of the machine which will be used to build the solutions selected.
The team project which will be built using this build type.
The directory on the build machine that will be used to build the
selected solutions. The directory must be a local path on the build
machine (e.g. c:\build).
The location to drop (copy) the built binaries and the log files after
the build is complete. This location has to be a valid UNC path of the
form \\Server\Share. The build machine service account and application
tier account need to have read write permission on this share.
Set this flag to enable/disable running tests as a post build step.
<!— WorkItemFieldValues
Add/edit key value pairs to set values for fields in the work item created
during the build process. Please make sure the field names are valid
for the work item type being used.
<WorkItemFieldValues>Symptom=build break;Steps To Reproduce=Start the build using Team Build</WorkItemFieldValues>
To change CodeAnalysis behavior edit this value. Valid values for this
can be Default,Always or Never.

Default – To perform code analysis as per the individual project settings
Always – To always perform code analysis irrespective of project settings
Never – To never perform code analysis irrespective of project settings
Set this flag to enable/disable updating associated workitems on a successful build
<!— Title for the work item created on build failure —>
<WorkItemTitle>Build failure in build:</WorkItemTitle>
<!— Description for the work item created on build failure —>
<DescriptionText>This work item was created by Team Build on a build failure.</DescriptionText>
<!— Text pointing to log file location on build failure —>
<BuildlogText>The build log file is at:</BuildlogText>
<!— Text pointing to error/warnings file location on build failure —>
<ErrorWarningLogText>The errors/warnings log file is at:</ErrorWarningLogText>
<!— Assembly version properties. Add others here —>

<!— TF.exe —>

<!— AssemblyInfo file spec —>

<!— Set this to non-existent file to force rebuild. —>
<IntermediateAssembly Include=“$(SolutionRoot)\foobar.dll”/>

The path of the solutions to build. To add/delete solutions, edit this
value. For example, to add a solution MySolution.sln, add following line –
<SolutionToBuild Include=”$(SolutionRoot)\path\MySolution.sln” />

To change the order in which the solutions are build, modify the order in
which the solutions appear below.
<SolutionToBuild Include=“$(SolutionRoot)\ConsoleApplication4.sln” />
The list of configurations to build. To add/delete configurations, edit
this value. For example, to add a new configuration, add following lines –
<ConfigurationToBuild Include=”Debug|x86″>

The Include attribute value should be unique for each ConfigurationToBuild node.
<ConfigurationToBuild Include=“Release|Any CPU”>
<PlatformToBuild>Any CPU</PlatformToBuild>
If the RunTest is set to true then the following test arguments will be
used to run tests.

To add/delete new testlist or to choose a metadata file (.vsmdi) file, edit this value.
For e.g. to run BVT1 and BVT2 type tests mentioned in the Helloworld.vsmdi file, add the following –

<MetaDataFile Include=”$(SolutionRoot)\HelloWorld\HelloWorld.vsmdi”>

Where BVT1 and BVT2 are valid test types defined in the HelloWorld.vsmdi file.
MetaDataFile – Full path to test metadata file.
TestList – The test list in the selected metadata file to run.

Please note that you need to specify the vsmdi file relative to $(SolutionRoot)
<MetaDataFile Include=” “>
<TestList> </TestList>
The list of additional reference paths to use while resolving references.
For example,
<AdditionalReferencePath Include=”C:\MyFolder\” />
<AdditionalReferencePath Include=”C:\MyFolder2\” />

<Target Name=“AfterGet” Condition=“‘$(IsDesktopBuild)’!=’true'”>
   <!— Set the AssemblyInfoFiles items dynamically —>
  <CreateItem Include=“$(SolutionRoot)\**\$(AssemblyInfoSpec)”>
<Output ItemName=“AssemblyInfoFiles” TaskParameter=“Include” />

<Exec WorkingDirectory=“$(SolutionRoot)”
Command=“$(TF) checkout /recursive $(AssemblyInfoSpec)”/>

<Target Name=“AfterCompile” Condition=“‘$(IsDesktopBuild)’!=’true'”>
<Exec WorkingDirectory=“$(SolutionRoot)”
Command=“$(TF) checkin /comment:&quot;Auto-Build: Version Update&quot; /noprompt /override:&quot;Auto-Build: Version Update&quot; /recursive $(AssemblyInfoSpec)”/>

  <!– In case of Build failure, the AfterCompile target is not executed. Undo the changes –>
<Target Name=“BeforeOnBuildBreak” Condition=“‘$(IsDesktopBuild)’!=’true'”>
<Exec WorkingDirectory=“$(SolutionRoot)”
Command=“$(TF) undo /noprompt /recursive $(AssemblyInfoSpec)”/>


Comments (4)

  1. Chandra Tiwary says:

    Hi Gautam,

    The post was excellent. It helped me immensely especially when I was playing with MSBuild for the first time. However, could you please clarify one issue:

    I do not understand the syntax <AssemblyInfoFiles Include="$(SolutionRoot)**$(AssemblyInfoSpec)"/>. What does ** mean here? I have a solution that has only one AssemblyInfo.cs file that lives at the same level as the solution file and gets shared by all the projects. In this scenario the above mentioned process does not work.

  2. Changgyu from&amp;nbsp;Avanade brought this interesting problem to my attention –

    If you are using Continuous…

  3. Wie versprochen hier die Informationen zum VSTS Techtalk Build Demo 🙂 Wenn man mit Team Foundation

  4. Gautam Goenka, dev lead for Team Build v1, wrote a blog post way back in January of 2004 that laid out