FailOnError 在自定义 NAnt 任务中不起作用
我有用于测试目的的自定义 NAnt 任务,如果任务失败,我想取消 NAnt 构建过程。 我创建了自定义 ErrorTask:
[NAnt.Core.Attributes.TaskName("errorTask")]
public class ErrorTask : NAnt.Core.Task
{
public ErrorTask()
{
FailOnError = true;
}
protected override void ExecuteTask()
{
Log(NAnt.Core.Level.Error, "Error!");
}
}
这是我在 NAnt 构建文件中的内容:
<target name="errorTarget">
<errorTask failonerror="true" />
<errorTask failonerror="true" />
</target>
在结果(build.log)中我有:
errorTarget:
[errorTask] Error!
[errorTask] Error!
BUILD SUCCEEDED - 2 non-fatal error(s), 0 warning(s)
Total time: 0 seconds.
所以,我可以看到第二个任务也运行了,但我想取消它,因为第一次调用返回“错误!”。你能帮我修复它吗?
另外,我认为没有必要对 FailOnError 值进行硬编码,在构建脚本中仅使用 failureonerror 属性就足够了,但在任何情况下它对我都不起作用。
谢谢。
I have custom NAnt task for test purposes and I would like to cancel NAnt build process if the task is failed.
I have created custom ErrorTask:
[NAnt.Core.Attributes.TaskName("errorTask")]
public class ErrorTask : NAnt.Core.Task
{
public ErrorTask()
{
FailOnError = true;
}
protected override void ExecuteTask()
{
Log(NAnt.Core.Level.Error, "Error!");
}
}
Here is what I have in NAnt build file:
<target name="errorTarget">
<errorTask failonerror="true" />
<errorTask failonerror="true" />
</target>
In the result (build.log) I have:
errorTarget:
[errorTask] Error!
[errorTask] Error!
BUILD SUCCEEDED - 2 non-fatal error(s), 0 warning(s)
Total time: 0 seconds.
So, I can see that second task is also run, but I would like to cancel it, because first call returns "Error!". Could you assist me to fix it?
Also, I assume, that it is not necessary to hardcode FailOnError value, it should be enough to use just failonerror attribute in build script, but it does not work for me in any case.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要让异常从 ExecuteTask 函数中冒出。在日志语句之后,添加以下行:
You need to let an exception bubble out of your ExecuteTask function. After your log statement, add this line: