如果目标失败,则停止msbuild进程 [英] Stop msbuild process if a target fails
问题描述
假设我有三个目标A,B和C.
C取决于B.
B取决于A.
如果运行msbuild /t:C mybuildfile.xml
,它将按顺序执行目标A,B和C.
我该如何设置以确保如果A中发生任何故障,C和B将不会执行?
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?
推荐答案
<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>
好的,我自己弄清楚了.使用上面的代码,如果目标A失败,它将转到OnError任务中指定的StopBuild.有关msbuild如何处理错误的更多信息,请转到 http://en.csharp-online.net/MSBuild:_By_Example%E2 %80%94Dealing_with_MSBuild_Errors
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
这篇关于如果目标失败,则停止msbuild进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!