NAnt SDK Documentation - v0.85-nightly-2005-11-09

LoopTask Class

[This is preliminary documentation and subject to change.]

Loops over a set of items.

For a list of all members of this type, see LoopTask Members.

System.Object
   NAnt.Core.Element
      NAnt.Core.Task
         NAnt.Core.TaskContainer
            NAnt.Core.Tasks.LoopTask

[Visual Basic]
<TaskName(Name:="foreach")>
Public Class LoopTask
    Inherits TaskContainer
[C#]
[TaskName(Name="foreach")]
public class LoopTask : TaskContainer

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

Can loop over files in directory, lines in a file, etc.

The property value is stored before the loop is done, and restored when the loop is finished.

The property is returned to its normal value once it is used. Read-only parameters cannot be overridden in this loop.

Example

Loops over the files in c:\.

                
            <foreach item="File" in="c:\" property="filename">
                <echo message="${filename}" />
            </foreach>
                
              

Loops over all files in the project directory.

                
            <foreach item="File" property="filename">
                <in>
                    <items>
                        <include name="**" />
                    </items>
                </in>
                <do>
                    <echo message="${filename}" />
                </do>
            </foreach>
                
              

Loops over the folders in c:\.

                
            <foreach item="Folder" in="c:\" property="foldername">
                <echo message="${foldername}" />
            </foreach>
                
              

Loops over all folders in the project directory.

                
            <foreach item="Folder" property="foldername">
                <in>
                    <items>
                        <include name="**" />
                    </items>
                </in>
                <do>
                    <echo message="${foldername}" />
                </do>
            </foreach>
                
              

Loops over a list.

                
            <foreach item="String" in="1 2,3" delim=" ," property="count">
                <echo message="${count}" />
            </foreach>
                
              

Loops over lines in the file properties.csv, where each line is of the format name,value.

                
            <foreach item="Line" in="properties.csv" delim="," property="x,y">
                <echo message="Read pair ${x}=${y}" />
            </foreach>
                
              

Requirements

Namespace: NAnt.Core.Tasks

Assembly: NAnt.Core (in NAnt.Core.dll)

See Also

LoopTask Members | NAnt.Core.Tasks Namespace