How To: Insert Custom Process at Specific Points During Build

Today Kieran, Faisal, and I met with one of our partners to give them an introduction to MSBuild. During the discussion one of them asked us about the different places someone can plug into the standard Visual Studio build process (as defined by the Microsoft.Common.Targets file).

In general the way you hook into the existing build process is by re-defining targets that exist in Microsoft.Common.Targets in either your project file or in your own .targets file. Faisal wrote about the specifics of what the XML looks like in an earlier post, but it doesn't look like we have a list of those targets documented anywhere (other than in Microsoft.Common.Targets!), so here's an easier to parse list:

Target Name Description
BeforeBuildAfterBuild These are primary for legacy support with prior versions of Visual Studio 2005. Tasks inserted in these targets will run before and after everything else in the build.
BeforeRebuildAfterRebuild Tasks inserted in these targets run before and after the core rebuild functionality is invoked. The flow is: BeforeRebuild, Clean, the default target (Build), and After Rebuild.
BeforeCleanAfterClean Tasks inserted in these targets run before and after the core clean functionality is invoked.
BeforePublishAfterPublish Tasks inserted in these targets run before and after the core publish functionality is invoked.
BeforeResolveReferencesAfterResolveReferences Tasks inserted in these targets run before and after assembly references are resolved.
BeforeCompileAfterCompile Tasks inserted in these targets run before and after core compliation is done. Typically most custom work is done in one of these two targets.
BeforeResGenAfterResGen Tasks inserted in these targets run before and after resources are generated.

[ Author: Neil Enns ]