yang-qu
yang-qu

Reputation: 2154

Stop msbuild process if a target fails

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?

Upvotes: 6

Views: 3510

Answers (1)

yang-qu
yang-qu

Reputation: 2154

<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

Upvotes: 7

Related Questions