views:

19

answers:

2

I'm encountering an issue with the <exec> task on batch files in my NAnt project files. When running on Windows XP SP 3 (but not Windows Vista or Windows Server 2008) and using NAnt 0.85 or 0.91alpha2, the <exec> task will always succeed (returning an error code of 0) regardless of what the executed script returned.

As an example, I wrote the following NAnt target:

<target name="build">
    <exec program="fail.bat"
    failonerror="false" resultproperty="makeall.result">
</exec>
<echo message="Makeall task returned result ${makeall.result}"/>
<fail if="${int::parse(makeall.result) != 0}">Encountered ${makeall.result} errors.</fail>
</target>

which calls the following batch file:

exit /b 1

Under normal operation (Windows Vista), the result of running NAnt is:

build:

     [exec] C:\Users\Will\Code>exit /b 1 
     [exec] C:\Users\Will\Code\fail.build(6,4):
     [exec] External Program Failed: C:\Users\Will\Code\fail.bat (return code was 1)
     [echo] Makeall task returned result 1

BUILD FAILED - 1 non-fatal error(s), 0 warning(s)

But on two different Windows XP SP3 machines, the result of running NAnt is:

build:

     [exec] C:\Documents and Settings\Will\My Documents\My Code>exit /b 1 
     [echo] Makeall task returned result 0

BUILD SUCCEEDED

Although I'm not discounting the possibility that this is a bug, I find it much more likely that I'm forgetting some crucial configuration setting on either Windows or NAnt that is causing this behavior. Has anyone else encountered this? Is there a reasonably elegant workaround?

A: 

Nant contains 2 functions that might be useful to you:

With these you might be able to write a target to generate an expected build result property. Then it should be possible to compare the expected result to the actual result returned. This way you can handle OS specific scenarios.

As for the 'root-cause' of the difference between the two results, I don't know why they would be different between versions of Windows.

TK
A: 

This is the format that we use, it always seems to work for us. the dexbuild .bat file contains

---------2.0 ------------- "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv" C:\YourProject\YourSoultion.sln /Rebuild release 

----------3.5-------------- "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv" C:\YourProject\YourSoultion.sln /Rebuild release 

similar logic for 4.0 

ccnet.config
       <tasks> 
              <nant> 
                <executable>C:\Nant\Nant0.86\bin\nant.exe</executable> 
                <baseDirectory>.</baseDirectory> 
                <buildFile>C:\NANT_SCRIPTS\build.xml</buildFile> 
                <targetList> 
                  <target>DexWeb</target> 
                </targetList> 
                <buildTimeoutSeconds>2000</buildTimeoutSeconds> 
              </nant>        
     </tasks> 

   build.xml file
        <target name="DexWeb"> 
            <exec program="C:\NANT_SCRIPTS\continous\dexbuild.bat" /> 
          </target>  
Kirit Chandran