Customizable Team Foundation Build Targets

MSBuild targets define how a 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. Each Team Foundation Build build type includes a project file that is named TfsBuild.proj. TfsBuild.proj imports the Microsoft.TeamFoundation.Build.targets file and provides values for various properties, item groups, and potentially overrides some of the extension point targets in the hierarchy.

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 extend other targets.

Target Name Description

BeforeEndToEndIteration

Insert your task into this target to run tasks before the EndToEndIteration target.

AfterEndToEndIteration

Insert your task into this target to run tasks after the EndToEndInteration target.

BuildNumberOverrideTarget

Used to override a target to customize the build number. 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 target.

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 before 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.

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 Foundation Build to Build a Visual Studio Setup Project.

BeforeTest

Called before tests are run. Insert your task into this target to run custom tasks before the Test target.

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, build log files, 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.

BeforeOnBuildBreak

Called before creating a work item on the build break. Insert your task into this target to run custom tasks before the BuildBreak target.

AfterOnBuildBreak

Called after a work item is created on the build break. Insert your task into this target to run custom tasks after the BuildBreak target.

Inserting Tasks into the Targets

The task code you write must be paired with a target. For more information, see How To: Write a Task. To write a custom task you must follow these steps.

  1. Write the task code, and check it into source control.

    Note

    It is good coding practice to check task code into source control, but it is not absolutely necessary.

  2. 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"/>
    
  3. Run the task by inserting it into the desired target in the TfsBuild.proj file.

    <Target Name="BeforeGet">
        <SimpleTask />
    </Target>
    
  4. Deploy the dll that contains the custom task on the build computer.

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 is in the following list.

  1. BeforeEndToEndIteration

  2. BuildNumberOverrideTarget

  3. InitializeEndToEndIteration

  4. BeforeClean

  5. CoreClean

  6. AfterClean

  7. Clean

  8. InitializeBuild

  9. InitializeWorkspace

  10. BeforeGet

  11. CoreGet

  12. AfterGet

  13. BeforeLabel

  14. CoreLabel

  15. AfterLabel

  16. PreBuild

  17. BeforeCompile

  18. CoreCompile

  19. AfterCompile

  20. Compile

  21. GetChangeSetsAndUpdateWorkItems

  22. PostBuild

  23. BeforeTest

  24. CoreTest

  25. AfterTest

  26. Test

  27. PackageBinaries

  28. TeamBuild

  29. BeforeDropBuild

  30. CoreDropBuild

  31. CopyLogFiles

  32. AfterDropBuild

  33. DropBuild

  34. AfterEndToEndIteration

  35. EndToEndIteration

See Also

Concepts

Understanding Team Foundation Build Configuration Files
Customizable Team Foundation Build Properties
Team Foundation Build Tasks