开发者

FailOnError does not work in custom NAnt task

开发者 https://www.devze.com 2023-01-20 20:05 出处:网络
I have custom NAnt task for test purposes and I would like to cancel NAnt build process if the task is failed.

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 nece开发者_Python百科ssary 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.


You need to let an exception bubble out of your ExecuteTask function. After your log statement, add this line:

throw new BuildException("Something terrible has happened!");
0

精彩评论

暂无评论...
验证码 换一张
取 消