Replicating OnSuccess and OnFailure in MSBuild
As you may have read in an earlier post, I'm currently helping a customer migrate their project from Visual Studio .NET 2003 to Visual Studio 2005. Our current build script uses NAnt, and we're in the process of converting it to MSBuild. Since we're big fans of continuous integration, and we depend on our Ambient Orb for at-a-glance build status, we have a need to replicate the behavior of NAnt's OnSuccess and OnFailure properties.
I wasn't able to find similar MSBuild functionality by browsing through the limited information I have (or can find on the internet), so I sent an e-mail to our internal team, and Alex Kipman was kind enough to suggest this solution:
<Project DefaultTargets="A;OnSuccess" >
<Target Name="A" DependsOnTargets="B;C;D" >
<OnError Targets="OnFailure" />
</Target>
<Target Name="OnFailure" >
<DoSomething />
</Target>
<Target Name="OnSuccess" >
<DoSomething />
</Target>
</Project>
Although this technique isn't as intuitive as the NAnt solution, it does work.
Comments
- Anonymous
October 07, 2004
Did they miss a "DependsOnTargets=A" in target "OnSuccess" ?
If this is not present, then targate A and OnSuccess might be executed in parallel, or?
Greetings
Jochen - Anonymous
October 08, 2004
Jochen:
No, the "DefaultTargets" on the Project tag specifies that Target A should be executed before Target OnSuccess. If "A" fails, it will run "OnFailure" and the build will complete. If no failure occurs while executing "A", then "OnSuccess" will be called and the build script will end. - Anonymous
October 09, 2004
Incorporating a Repository in the Virtual Cellar - Anonymous
October 25, 2004
<a href=http://www.street-blowjobs.net/milfhunter/120/worldporn.html>free adult</a>