Anyone who was worked with MSBuild to customize Team Build knows the pains of debugging your build scripts and that many times it resorts to outputting property and item values out with the message task. There is also the major issue of just knowing what each built in property contains and not mixing one up with another which gives you unexpected results. In order to simplify the output of the built in properties and easily give a complete list of their values, we compiled the property reference from Aaron Hallberg’s blog into a single targets file.
The screen shots below detail how the targets file is set up, how to use it within your build, and the output it produces. You can find a link to download the targets file at towards the end of the post.
The screen shot below shows an example of the custom target that was created to hold the sets of build in properties. A PropertyGroup named ExtensibleProperties contains the built in property name and then value with each separated by a blank line (%0D%0A).
ShowAllProperties Message Output
Once all the property groups are defined for the various property category types, a message task is used to output them to the build log.
ShowAllProperties File Output
Code is also added using the WriteLinesToFile task to append all the information to a file called TeamBuildProperties.txt. Notice there is no file path defined so the current output location of the file is the working directory of MSBuild during a TeamBuild. If your build agent working directory is defined as C:Work$(BuildDefinitionPath), your Team Project is Project1, and your build definition is Build1, the local path where you would find the file would be C:WorkProject1Build1BuildTypeTeamBuildProperties.txt.
Targets File in Source Control
The TeamBuild.Properties.targets file where the ShowAllProperties target is defined is added to source control alongside the Team Build project definition. Of course, in most instance you will want to be using this file across multiple build definitions so you would be better off storing it in a shared location and branching it into each project or using another strategy to maintain a single master copy in source control that can be easily maintained and utilized by multiple build defnitions.
Import Statement in TFSBuild.proj
An Import statement is used to pull the TeamBuild.Properties.targets file into the Team Build TFSBuild.proj file. Since the targets file is added to source control at the same level as the Team Build project file, the $(MSBuildProjectDirectory) property is used to target this location.
To execute the target, the CallTarget task is used and called in the BeforeTest target in the example below.
Extensible Properties Output
The start of the property output is easily found within the build log by searching for **** which breaks up the various property categories. Then you can see the property name and values at the time of the execution for the various categories as seen by the screen shots below.
Get Task Properties Output
Label Task Properties Output
Read Only Properties
You can download the custom targets file here TeamBuild.Properties.targets to use within your own build scripts.
I hope the ease of the targets file will help you in debugging your build scripts or stepping into team build for the first time and exploring the built in properties. Automate your builds and enjoy!