Search code examples
antnant

What are the alternatives for <first> in NAnt?


In Ant you can use the following script:

 <first id="first">
        <fileset dir="dir.zips" includes="**/a.zip" />
 </first>
 <echo message="${toString:first}" />

to get the first file from the filelist.

Is there any alternative for the same in NAnt. <First> is not a valid task in NAnt.


Solution

  • I found an alterative, though it is not efficient

    <property name="iter" value="0" overwrite="true"/>
    <property name="first" value="" overwrite="true"/>
    <foreach item="file" property="filename" in"src\build">
        <do>
            <if test="${iter == '0'}">
                <property name="first" value="${filename}" overwrite="true"/>
            </if>
        <do>
        <property name = "iter" value="${int::parse(iter) + 1}"/>
    </foreach> 
    

    Since the loop won't break after first iteration, I have decided to create a custom task.