Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop msbuild process if a target fails

Tags:

msbuild

Let's say I have three targets A, B and C. C depends on B. B depends on A. If I run msbuild /t:C mybuildfile.xml, it will execute target A, B and C in order. How do I set up to make sure C and B won't get executed if there is anything failed in A?

like image 753
yang-qu Avatar asked Jul 21 '10 07:07

yang-qu


1 Answers

<Target Name="StopBuild">
    <Message Text="An error has occurred, build stopped." />
</Target>

<Target Name="A">
    <OnError ExecuteTargets="StopBuild"/>
</Target>

<Target Name="B" DependsOnTargets="A">

</Target>

Ok, I figured out this by myself. Use the code above, if target A fails, it will go to StopBuild specified in OnError task. For more on how msbuild handles errors, go to http://en.csharp-online.net/MSBuild:_By_Example%E2%80%94Dealing_with_MSBuild_Errors

like image 75
yang-qu Avatar answered Nov 15 '22 12:11

yang-qu