Calling Custom Targets Within Team Build, Part 2

First of all, sorry for the long delay between posts...  Things have been a bit crazy around here trying to meet various deadlines lately, and blogging fell right off my radar for a while.  Having said that, I've got a pretty big backlog of posts to get done, so hopefully I'll get a bunch posted here in the near future.

I've gotten several questions over the past month or so on calling custom targets defined in TfsBuild.proj for each solution/project built and/or for each configuration (e.g. Debug / Any CPU) built.  I did a post a while back on calling custom targets, but it was mostly focused on calling targets other than the default (typically "Build") in the solutions/projects included in the SolutionToBuild item group within TfsBuild.proj.  That is, these custom targets would be in the solution / project itself, not in TfsBuild.proj.

In Team Build 2008, we added several new extension points that allow you to execute custom targets within TfsBuild.proj before / after the compilation of individual solution and/or configurations.  In particular, in Team Build 2005 the compilation portion of the build process included just the following targets (with targets designed to be overridden given in bold):




And that was it...  CoreCompile built every solution for every configuration.  If you wanted to inject some custom logic anywhere other than before this entire process or after this entire process, you were basically out of luck.  In Team Build 2008, the compilation portion of the build process includes the following targets:



    (for each configuration)



        (for each solution)






Additionally, several properties are available in the relevant spots in this process to help you execute logic conditionally.  In particular, within each iteration of the *CompileConfiguration targets, the properties $(Platform) and $(Configuration) will provide the currently compiling platform and configuration; and within each iteration of the *CompileSolution targets, the property $(Solution) will provide the currently compiling solution. 

So - to execute custom logic for each solution, you can either insert that logic directly into the Before/AfterCompileSolution target, use the CallTarget task to explicitly call your target, etc.