Base Team Build Template V1

Having a base working set of Team Build’s templates is a critical to a healthy build system. One of the ways I have found over the years is to have a base template that will write out into the log file out my custom variables.  This way I can verify that the custom variable is correct when troubleshooting more complex build template.

Applies to

  • Team Foundation Server 2012 (TFS)
  • Team Build
  • Small buildable project


  • TFS
  • Base knowledge of Team Build


When troubleshooting a build issue, verifying that the custom variables in the team build template are correct at the start does reduces time spend in finding the build issue.


Using the Team Build default template, I will create some custom variable and have a these variable write out to a build log file.  I then can verify that the variables and the paths  are correct.  To start we will need to create a new version 1 template:

1. Open Visual Studio | Click on Builds | Right click on a working build | Select Edit Build Definition…. | The build definition will open

Figure 1image

2. Click on Process | Click on Show details | The Build process template list will appear

Figure 2image

3. In the Build Process Template | Click on New | The New Build Process Template menu will appear

4. In the New file name: | Rename the new template | Click OK | A new build template will be created

Figure 3image

5. Click on the hyper link to open the new build template location | Get latest version to your local workspace

Figure 4image

Figure 5image

6. Double click on the new build template | The new build template will open in Visual Studio

7. In the upper right Click on Collapse All | This will collapse the build template sequences

Figure 6

8. On the Run on Agent click on the down arrow | The Run on Agent sequence will open

Figure 7 image

9. Click on Initialize Variables sequence |  Right click on  “Initialize TestResults Directory” activity and select Copy | Right click below the original  “Initialize TestResults Directory” activity can paste the copy version | This will create a copy of the “Initialize TestResults Directory” activity

Figure 8

10. Right click on the copied “Initialize TestResults Directory” activity | The menu will appear | Click on Create Variable | The Variables will appear

11. Enter the name of a new Variable, example DeploymentScripts | Change Scope to Run on Agent

12. Click on the copied “Initialize TestResults Directory” activity |  In the Properties Change the following

Display Name

“Initialize DeploymentScriptFolder Directory”




String.Format("{0}BuildProcessTemplatesDeploymentScripts", SourcesDirectory)

Figure 9

NOTE You will need to create a folder in the BuildProcessTemplates folder named DeploymentScripts

13. Save the template

14. Open the Toolbox | Control Flow | Select Sequence and drag a new Sequence un the If WorkspaceName > sequence

Figure 10

15. Expand the Sequence and add a If activity | In the Then box |Add a Sequence

16. Expand the Sequence | Add WriteBuildMessage activity under the Team Foundation Build Activity in the Toolbox

Figure 11

17. In the Arguments section enter a new argument to turn on or off the write message sequence



Argument type


Default value to


18. In the property of top Sequence | Change the Display Name to DeploymentScript

19. In the If activity |  Enter in the Condition  VariablesOutPutOnOff=True

20. In the Sequence in the Then area | Change the DisplayName to Write Variables To Log

21. In the WriteBuildMessage enter the following


WriteBuildMessage DeploymentScript Folder Path




String.Format("Custom-Build Deployment folder on Build Agent: {0}", DeploymentScripts)

22. Save  and check-in the updated template into source control

Figure 12

23. Queue a new build using the updated build template that you created

24. Make sure the argument for VariablesOutPutOnOff is set to true in the Process section

Figure 13

25. After the build has ran | Open the log file | The new Write Variables To Log will appear

Figure 14


I have found this basic tasks of writing custom and something standard variables to the log file very handy when troubleshooting build issues.  There has been many time when I thought the path was correct, only to find that it was not valid.  This way I can find out if that path and the variables values are correct.

Additional resources

Configuring and Managing Your Build System

Team Foundation Build Customization Guide


Team Build Activities

WPF MSBuild Reference

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s