Kit*_*Kit 3 nant properties expansion fileset
我有一组目标,每个目标基本上都是相同的,除了每个目标包含一个特定的模式集,在其上执行其任务.我想将这些目标折叠成一个"可重用"的目标,而是将一组文件"作为参数".
例如,这个
<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>
Run Code Online (Sandbox Code Playgroud)
将被替换为
<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>
Run Code Online (Sandbox Code Playgroud)
然而,事实证明,由于模式集和文件集与属性不同,因此refid在nant-dev电子邮件发布中没有得到扩展.在这个非工作代码中,当echo调用它时,它的patternset元素引用一个名为$ {sourcefiles}的模式集,而不是名为test的模式集.
如何写一个可以在不同文件集上运行的可重复使用的NAnt目标?有没有办法在NAnt中按原样执行此操作而无需编写自定义任务?
我终于想出了这个,这符合我的目的.作为奖励,这也证明了动态调用目标.
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1171 次 |
| 最近记录: |