Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4028876
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:16:30+00:00 2026-05-20T11:16:30+00:00

I have a set of targets that each do essentially the same thing except

  • 0

I have a set of targets that each do essentially the same thing except each contains a specific patternset on which to perform its tasks. I want to collapse these targets into a single “reusable” target that instead takes a set of files “as a parameter”.

For example, this

<target name="echo1">
  <foreach item="File" property="fn">
    <in>
      <items>
        <include name="*.config"/>
      </items>
    </in>
    <do>
      <echo message="${fn}" />
    </do>
  </foreach>
</target>

<target name="echo2">
  <foreach item="File" property="fn">
    <in>
      <items>
        <include name="*.xml"/>
      </items>
    </in>
    <do>
      <echo message="${fn}" />
    </do>
  </foreach>
</target>

<target name="use">
  <call target="echo1"/>
  <call target="echo2"/>
</target>

would be replaced by

<patternset id="configs">
   <include name="*.config"/>
</patternset>

<patternset id="xmls">
   <include name="*.xml"/>
</patternset>

<target name="echo">
  <foreach item="File" property="fn">
    <in>
      <items>
        <patternset refid="${sourcefiles}"/>
      </items>
    </in>
    <do>
      <echo message="${fn}" />
    </do>
  </foreach>
</target>

<target name="use">
  <property name="sourcefiles" value="configs"/>
  <call target="echo"/>
  <property name="sourcefiles" value="xmls"/>
  <call target="echo"/>
</target>

However, it turns out that refid is not expanded as answered in a nant-dev email posting because patternsets and filesets differ from properties. In this non-working code, when echo is called, its patternset element references a patternset literally named ${sourcefiles} instead of the one named test.

How would one write a re-usable NAnt target that operates on a varying set of files? Is there a way to do this in NAnt as-is without resorting to writing custom tasks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:16:30+00:00Added an answer on May 20, 2026 at 11:16 am

    I finally came up with this, which serves my purposes. As a bonus, this also demonstrates calling a target dynamically.

    <project
      name="dynamic-fileset"
      default="use"
      xmlns="http://nant.sourceforge.net/release/0.86-beta1/nant.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
        <target name="configs">
            <fileset id="files">
               <include name="*.config"/>
            </fileset>
        </target>
    
        <target name="xmls">
            <fileset id="files">
               <include name="*.xml"/>
            </fileset>
        </target>
    
        <target name="echo">
          <foreach item="File" property="fn">
            <in>
              <items refid="files"/>
            </in>
            <do>
              <echo message="${fn}" />
            </do>
          </foreach>
        </target>
    
        <target name="use">
          <property name="grouplist" value="xmls,configs"/>
          <foreach item="String" in="${grouplist}" delim="," property="filegroup">
            <do>
              <call target="${filegroup}"/>
              <call target="echo"/>
            </do>
          </foreach>        
        </target>
    </project>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do you have some predefined set of targets which all build.xml files you create
I have a table set up such that each row has a checkbox as
I have set up multiple targets in a single xml file. I expect all
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set of flat files (114 files) each file is named with database
We have a series of products with built in web servers each of which
I currently have a set of buttons that I would like to set triggers
I have two absolutely positioned div elements that overlap. Both have set z-index values
I have a project with multiple modules, each in its own directory. Each module
I have a set of 100 observations where each observation has 45 characteristics. And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.