views:

272

answers:

2

I have an NAnt task "ship" to package my current .sql scripts into a build, then name the build with an incrementing int {######} and copy it to a build folder. I have another NAnt task which executes those build scripts. They must execute in order, but in my last attempt, they were not. Can I "force" NAnt to work alphabetically?

Thanks;

Duncan

A: 

To satisfy my curiosity I tried to reproduce the problem with this script:

<?xml version="1.0"?>
<project name="foreach.test" default="foreach.alpha">
  <target name="foreach.alpha">
    <foreach item="File" in="C:\foo" property="filename">
      <do>
        <echo message="${filename}" />
      </do>
    </foreach>
  </target>
</project>

The filenames are printed out in alphabetical order. So conventional use of foreach already seems to be the solution to the problem.

The Chairman
How did you prettify your XML?
Duncan
+2  A: 

FAIL:

<fileset basedir="source\tsql\builds\" id="buildfiles">
  <include name="*.sql.template.sql" /> 
  <exclude name="*.sql" /> 
  <exclude name="*asSentTo*" />
</fileset>
<foreach item="File" property"filename">
  <in refid="buildfiles">
    <echo message="${filename}" /> 
  </in>
</foreach>

PASS:

<foreach item="File" property="filename" in="source\tsql\builds"> 
  <do> 
    <if test="${string::ends-with(filename,'.sql.template.sql')}"> 
      <echo message="${filename}" /> 
    </if> 
  </do> 
</foreach>
Duncan
Duncan to format the XML or code you need to add at least 4 spaces before each line. You had 2. I edited to format it. You can also select the text and use the code block icon (ones and zeros on the icon). You can click edit to see what I did.
Ahmad Mageed
Thank you, Ahmad!
Duncan