Replicating OnSuccess and OnFailure in MSBuild

Replicating OnSuccess and OnFailure in MSBuild

  • Comments 4

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.

Leave a Comment
  • Please add 5 and 3 and type the answer here:
  • Post
  • 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
  • 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.
  • Incorporating a Repository in the Virtual Cellar
  • <a href=http://www.street-blowjobs.net/milfhunter/120/worldporn.html>free adult</a>
Page 1 of 1 (4 items)