I've done a couple of posts now on calling custom targets during a Team Build build - this one focused on calling custom targets in the solution/project being built, and this one focused on calling custom targets in your TfsBuild.proj file itself before/after the compilation of individual solutions or configurations. In the past week I've gotten two questions on whether one can call custom targets before/after the compilation of individual projects within a solution. That is, whether Microsoft.TeamFoundation.Build.targets supports Before/AfterCompileProject targets in the same way it supports Before/AfterCompileConfiguration and Before/AfterCompileSolution ones.
The short answer is that this is not really supported in Team Build 2008 (or 2005, for that matter), since by the time your solutions are getting built we have essentially ceded control to MSBuild. There are three potential methods (that I could think of) for doing this sort of thing:
This last option strikes me as the best one when including simplicity in the calculation... The targets file would look something like this:
<?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <!-- Only execute this custom logic when the project is building under Team Build. --> <Target Name="AfterBuild" Condition=" '$(TeamBuildConstants)' == '_TEAM_BUILD_' "> <!-- Put your custom logic here. --> </Target> </Project>
You would then check this targets file in alongside your TfsBuild.proj file and import it into your individual projects after the import of Microsoft.Common.targets using a relative path. For example, the end of a *.csproj file might look like:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="..\..\TeamBuildTypes\SomeDefinition\AfterCompileProject.targets"/> </Project>