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.

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

  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>
    

    Note

    Adding this tag causes XML schema warnings. You can safely ignore those warnings.

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

  1. InitializeBuildProperties

  2. BeforeEndToEndIteration

  3. BuildNumberOverrideTarget

  4. InitializeEndToEndIteration

  5. BeforeInitializeWorkspace

  6. CoreInitializeWorkspace

  7. AfterinitializeWorkspace

  8. InitializeBuild

  9. BeforeGet

  10. CoreGet

  11. AfterGet

  12. BeforeLabel

  13. CoreLabel

  14. AfterLabel

  15. BeforeClean

  16. CoreCleanCompilationOutput

  17. AfterClean

  18. BeforeCompile

  19. CoreCompile (for each platform/configuration combination)

  20. BeforeCompileConfiguration

  21. CoreCompileConfiguration (for each solution to build)

  22. BeforeCompileSolution

  23. CoreCompileSolution

  24. AfterCompileSolution

  25. AfterCompileConfiguration

  26. AfterCompile

  27. BeforeGetChangesetsAndUpdateWorkItems

  28. CoreGetChangeSetsAndUpdateWorkItems

  29. AfterGetChangesetsAndUpdateWorkItems

  30. BeforeTest

  31. CoreTest (for each platform/configuration combination)

  32. BeforeTestConfiguration

  33. CoreTestConfiguration

  34. AfterTestConfiguration

  35. AfterTest

  36. GenerateDocumentation

  37. BeforeDropBuild

  38. CoreDropBuild

  39. AfterDropBuild

  40. AfterEndToEndIteration

  1. InitializeBuildProperties

  2. BeforeEndToEndIteration

  3. BuildNumberOverrideTarget

  4. InitializeEndToEndIteration

  5. BeforeInitializeWorkspace

  6. CoreInitializeWorkspace

  7. AfterInitializeWorkspace

  8. BeforeClean

  9. CoreClean

  10. AfterClean

  11. InitializeBuild

  12. BeforeGet

  13. CoreGet

  14. AfterGet

  15. BeforeLabel

  16. CoreLabel

  17. AfterLabel

  18. BeforeCompile

  19. CoreCompile (for each platform/configuration combination)

  20. BeforeCompileConfiguration

  21. CoreCompileConfiguration (for each solution to build)

  22. BeforeCompileSolution

  23. CoreCompileSolution

  24. AfterCompileSolution

  25. AfterCompileConfiguration

  26. AfterCompile

  27. BeforeGetChangesetsAndUpdateWorkItems

  28. CoreGetChangeSetsAndUpdateWorkItems

  29. AfterGetChangesetsAndUpdateWorkItems

  30. BeforeTest

  31. CoreTest (for each platform/configuration combination)

  32. BeforeTestConfiguration

  33. CoreTestConfiguration

  34. AfterTestConfiguration

  35. AfterTest

  36. GenerateDocumentation

  37. BeforeDropBuild

  38. CoreDropBuild

  39. AfterDropBuild

  40. AfterEndToEndIteration

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.

  1. SetBuildBreakProperties

  2. BeforeOnBuildBreak

  3. GetChangesetsOnBuildBreak

  4. BeforeDropBuild

  5. CoreDropBuild

  6. AfterDropBuild

  7. BeforeCreateWorkItem

  8. CoreCreateWorkItem

  9. AfterCreateWorkItem

  10. CoreOnBuildBreak

  11. AfterOnBuildBreak

See Also

Concepts

Understanding Team Foundation Build Configuration Files

Customizable Team Foundation Build Properties