nant

Nant foreach include exclude filter not working as expected


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>


Solution

  • 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">