Nant foreach include exclude filter not working as expected

2.5k Views Asked by At

I wish to exclude particular files from a nant (0.91) target and process the remainder.
Here's the code snippet, which shows I want to include all .js files but exclude foo. foo is not being excluded. I've tried putting the exclude before the include but same result.

<foreach item="File" in="${built.web.directory}\Content\js" property="filename">
  <in>
    <items basedir="${built.web.directory}\Content\js">
      <include name="/**/*.js" />
      <exclude name="**/foo.1.2.js" />
    </items>
  </in>
  <do>
    <echo message="Compressing ${filename}" />
    <exec
      program="${packer.exe}"
      commandline="-o ${built.web.directory}\Content\js\${path::get-file-name(filename)} -m jsmin ${filename}"
    />
  </do>
</foreach>

2

There are 2 best solutions below

0
On BEST ANSWER

You have specified the in attribute on foreach which is overriding the items element. Try changing:

<foreach item="File" in="${built.web.directory}\Content\js" property="filename">

to:

<foreach item="File" property="filename">
1
On

This seems to work:

<fileset id="javascript.files" basedir="${built.web.directory}\Content\js">
  <include name="/**/*.js" />
  <exclude name="**/foo.1.2.js" />
  <exclude name="**/*.min.js" />
</fileset>

<foreach item="File" property="filename">
  <in>
    <items refid="javascript.files" />
  </in>
  <do>
    <echo message="Compressing ${filename}" />
    <exec
      program="${packer.exe}"
      commandline="-o ${built.web.directory}\Content\js\${path::get-file-name(filename)} -m jsmin ${filename}"
    />
  </do>
</foreach>