NAnt include/exclude pattern to include root bin folder but not child bin folders

StackOverflow https://stackoverflow.com/questions/16676276

  •  30-05-2022
  •  | 
  •  

Question

How can I craft up a NAnt include/exclude pattern to include the root /bin directory and its files, but exclude bin directories that are children of other directories?

<target name="createArtifacts">
  <copy todir="${destdir}" includeemptydirs="false">
    <fileset basedir="${sourcedir}">
      <include name="**" /> <!-- this will get the root \bin folder -->
      <exclude name="**\bin\*.pdb" />
      <exclude name="**\bin\*.xml" />
      ...
    </fileset>
  </copy>
</target>

I want this to exclude any bin folder that is not the root bind folder:

<exclude name="\**\bin\" />

But it ends up removing the root bin as well.

Was it helpful?

Solution

You have been very close to the answer. You should just add an asterisk as a very first character in the exclude pattern. Taking your sample, this will loot like this:

<target name="createArtifacts">
  <copy todir="${destdir}" includeemptydirs="false">
    <fileset basedir="${sourcedir}">
      <include name="**" />
      <exclude name="*\**\bin\*.pdb" />
      <exclude name="*\**\bin\*.xml" />
      ...
    </fileset>
  </copy>
</target>

That first asterisk basically means "we don't want to take first-level folder into consideration".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top