Customizable Team Foundation Build Targets
MSBuild targets define how an MSBuild project is built. The Microsoft.TeamFoundation.Build.targets file defines the target hierarchy and a set of predefined MSBuild tasks and targets for Team Foundation Build used for all Team Foundation Build types. Build definitions include a project file that is named TfsBuild.proj. The project file can be associated with only one build definition, or with multiple build definitions. TfsBuild.proj imports the Microsoft.TeamFoundation.Build.targets file and provides values for various properties and item groups. You can customize the TfsBuild.proj file to override some of the extension point targets in the hierarchy. The targets file is located in <root>:\Program Files\MSBuild\Microsoft\VisualStudio\TeamBuild on the build agent.
Important
Do not modify the Microsoft.TeamFoundation.Build.targets file.
For more information about MSBuild targets, see MSBuild Targets.
Targets that can be Customized with Tasks
Tasks are contained in targets. Tasks provide the code that runs during the build process. The following table lists all the Team Foundation Build targets that are defined for extensibility. Insert your tasks into one of these targets depending on when you must run your custom tasks during the build process.
Note
We do not recommend that you override other targets.
Target Name |
Description |
---|---|
BeforeEndToEndIteration |
Insert your task into this target to run custom tasks at the very beginning of the build process. |
AfterEndToEndIteration |
Insert your task into this target to run custom tasks at the end of the build process. |
BeforeInitializeWorkspace |
Insert your task into this target to run custom tasks before workspace initialization. |
AfterInitializeWorkspace |
Insert your task into this target to run custom tasks after workspace initialization. |
BuildNumberOverrideTarget |
Insert your task into this target to customize the build number or drop location properties. The task you write must create an output property called BuildNumber. |
BeforeClean |
Called before clean is tried. Insert your task into this target to run pre-clean custom task. |
AfterClean |
Called after clean is completed. Insert your task into this target to run post-clean custom tasks. |
BeforeGet |
Called before sources are retrieved from source control. Insert your task into this target to run custom tasks before sources are retrieved. |
AfterGet |
Called after sources are retrieved. Insert your task into this target to run custom tasks after sources are retrieved. |
BeforeLabel |
Called before sources are labeled. Insert your task into this target to run custom tasks before the Label target. |
AfterLabel |
Called after labeling is completed. Insert your task into this target to run custom tasks after the Label target. |
BeforeCompile |
Called before compilation is started. Insert your task into this target to run custom tasks before the code files are compiled. |
BeforeCompileConfiguration |
Insert your task into this target to run custom tasks before the compilation of an individual configuration. |
BeforeCompileSolution |
Insert your task into this target to run custom tasks before the compilation of an individual solution. |
AfterCompileSolution |
Insert your task into this target to run custom tasks after the compilation of an individual solution. |
AfterCompileConfiguration |
Insert your task into this target to run custom tasks after the compilation of an individual configuration. |
AfterCompile |
Called after compilation is completed. Insert your task into this target to run custom tasks after the code files are compiled. |
BeforeGetChangesetsAndUpdateWorkItems |
Insert your task into this target to run custom tasks before associating changesets and updating work items. |
AfterGetChangesetsAndUpdateWorkItems |
Insert your task into this target to run custom tasks after associating changesets and updating work items. |
BeforeTest |
Called before tests are run. Insert your task into this target to run custom tasks before the Test target. |
BeforeTestConfiguration |
Insert your task into this target to run custom tasks before the testing of an individual configuration. |
AfterTestConfiguration |
Insert your task into this target to run custom tasks after the testing of an individual configuration. |
AfterTest |
Called after testing is completed. Insert your task into this target to run custom tasks after the Test target. |
BeforeDropBuild |
Called before saving the built binaries, build log files, and test results to the build-drop directory on the release server. Insert your task into this target to run custom tasks before the built files are saved to the drop directory. |
AfterDropBuild |
Called after dropping the built binaries and test results to the release server. Insert your task into this target to run custom tasks after the built files are saved to the drop directory. |
BeforeCreateWorkItem |
Insert your task into this target to run custom tasks before work item creation. |
AfterCreateWorkItem |
Insert your task into this target to run custom tasks after work item creation. |
BeforeOnBuildBreak |
Called before creating a work item as a result of a build break. Insert your task into this target to run custom tasks before the BuildBreak target. |
AfterOnBuildBreak |
Called after a work item is created as a result of a build break. Insert your task into this target to run custom tasks after the BuildBreak target. |
GenerateDocumentation |
This is an empty target. Insert your task into this target to generate documentation during the build process. |
Overriding Targets to Run Custom Tasks
The task code you write must be paired with a target. For more information, see Task Writing. To write a custom task, you must follow these steps.
Write the task code, and be sure the built binaries are available on the build computer, either by providing the source control path in the TfsBuild.proj file or by making the binaries available on the build computer itself.
Note
It is good coding practice to check task code into source control, but it is not absolutely necessary.
Register the custom task in the TfsBuild.proj file by declaring it using the UsingTask MSBuild element.
For more information, see UsingTask Element (MSBuild).
<UsingTask TaskName="MyTasks.SimpleTask" AssemblyName="MyAssembly.Build.Tasks"/>
Run the task by inserting it into the desired target in the TfsBuild.proj file.
<Target Name="BeforeGet"> <SimpleTask /> </Target>
Note
Adding this tag causes XML schema warnings. You can safely ignore those warnings.
Deploy the DLL that contains the custom task on the build computer.
Important
Every build definition that is associated with the TfsBuild.proj file you customize is affected by the change.
Order of Target Execution
The order of execution of the targets depends on the value of the CleanCompilationOutputOnly property. If CleanCompilationOutputOnly is true, the clean targets (BeforeClean, CoreClean and AfterClean) are executed after the get and label targets (BeforeGet, CoreGet, AfterGet, BeforeLabel, CoreLabel, and AfterLabel). If the CleanCompilationOutputOnly property is false, the clean targets are executed before the get and label targets. If CleanCompilationOutputOnly is true, only the intermediate assemblies are deleted from the sources directory during the CoreClean target execution. If this property is set to false, the entire sources directory will be deleted during CoreClean target execution.
The following table shows the ordered list of targets that are executed based on if CleanCompilationOutputOnly is true or false. The targets that you can override are displayed in bold text.
CleanCompilationOutputOnly = true |
CleanCompilationOutputOnly = false |
---|---|
|
|
The following is the list of targets that are executed when an error occurs during the execution of the CoreCompile target. The targets that you can override are displayed in bold text.
SetBuildBreakProperties
BeforeOnBuildBreak
GetChangesetsOnBuildBreak
BeforeDropBuild
CoreDropBuild
AfterDropBuild
BeforeCreateWorkItem
CoreCreateWorkItem
AfterCreateWorkItem
CoreOnBuildBreak
AfterOnBuildBreak