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 ]
Comments
- Anonymous
November 29, 2005
"it doesn't look like we have a list of those targets documented anywhere (other than in Microsoft.Common.Targets!)"
There is this post on the MSBuild forum at:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=58137&SiteID=1
By Dan Moseley - Anonymous
November 30, 2005
Yes, Dan's on our team and he wrote a great post in the forum. It doesn't, however, include the specific list of targets you can override in the build process.
Neil - Anonymous
May 04, 2006
Hi guys
I'm trying to obfuscate an assembly. It works fine until I go to publish, that's when the compiler publishes an assembly without the obfuscation.
How can I obfuscate my assembly so that it gets published as obfuscated? At what build target should i obfuscate? I tried the BeforePublish target but nothing seems to happen. Any ideas? - Anonymous
May 09, 2006
online directory main - Anonymous
September 29, 2006
About a week ago a VB developer, who I was giving an overview to an .NET application, asked about creating - Anonymous
October 01, 2009
From the description of BeforeBuild and AfterBuild "These are primary for legacy support ..." Is this being confused with the PreBuildEvent and PostBuildEvent target/properties? While I don't like BeforeBuild and AfterBuild targets myself too much, I still suggest people to use it for non-reusable project files.