开发者

How do I return a specific exit code from NANT?

I have a nant script and I see that 开发者_JS百科even if my exec fails, the exit code of NANT is 0 anyway. How do I change NANT exit code?


The exec task has an attribute called "resultproperty", which is there to get the exit code.


Returning a Specific Exit Code from NANT

If the build succeeds NANT will exit with code 0, if the build fails NANT with code 1 and you can use <fail> to force this. NANT gives no other way of controlling the exit code however you could hack it:

<script language="C#">
    <code>
        <![CDATA[
        public static void ScriptMain(Project project) 
        { 
            System.Environment.Exit(3);
        }
        ]]>
    </code>
</script>

This will end nant immediately, so perhaps you might want to create a target to be run at the very end by putting it into nant.onsuccess.

Why NANT Exit Code is 0 when <exec> Failed?

<exec> fails when the command exits with anything but 0. Normally this causes the whole build to fail in consequence and NANT to exit with code 1, with two exceptions (see 2 and 3). This gives us three possible explanations:

  1. Your command fails but exits with 0 anyway (this is a relatively common behavior). Set the resultproperty attribute and check the property.
  2. failonerror="False" attribute has been set on <exec> or on a higher level (<nant> or <call>). Check the NANT output to see in which order targets are being called or search for failonerror=.
  3. The <exec> is executed as part of target started via the nant.onsuccess resp. nant.onfailure property hook. Check if and where by searching for nant.on.

To say anything more a sample NANT script or perhaps a log file would be useful.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜