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 Note: |
---|
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 that depend 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 start 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 the 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. For an example, see Walkthrough: Configuring Team Build to Build a Visual Studio Setup Project. |
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 the 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 that resulted from 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 and the built binaries must be 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. You must also register the custom task in the TfsBuild.proj file by declaring it using the UsingTask MSBuild element. For more information, see UsingTask Element (MSBuild). Lastly, deploy the DLL that contains the custom task on the build computer.
Important Note: |
---|
Every build definition that is associated with the TfsBuild.proj file that you customize is affected by the change. |
For an example of an end-to-end implementation of a custom task, see Walkthrough: Customizing Team Foundation Build with a Custom Task.
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, all of the sources directory will be deleted during CoreClean target execution.
The following table shows the ordered list of targets that are executed based on whether CleanCompilationOutputOnly is true or false. The targets that you can override are indicated.
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 indicated.
SetBuildBreakProperties
BeforeOnBuildBreak (can override)
GetChangesetsOnBuildBreak
BeforeDropBuild (can override)
CoreDropBuild
AfterDropBuild (can override)
BeforeCreateWorkItem (can override)
CoreCreateWorkItem
AfterCreateWorkItem (can override)
CoreOnBuildBreak
AfterOnBuildBreak (can override)
See Also
Tasks
Concepts
Understanding Team Foundation Build Configuration Files