NAnt:检查是否已包含include文件

时间:2010-10-14 11:06:33

标签: nant

有人知道检查文件是否已包含的方法吗?

<include buildfile="${script.dir}\util.include.nant" />
.
.
.
.
<include buildfile="${script.dir}\util.include.nant" />

这将抛出目标重复的异常。有办法吗?

提前致谢

2 个答案:

答案 0 :(得分:1)

刚刚看到似乎相关的this question,并决定在我的其他答案中更改a.build中的一个重复包含的情况:

<include buildfile="c.build" />
<include buildfile="C.build" />

轰隆 - 重复目标错误。看起来nant足够明亮,可以忽略重复包含,但在比较它们时会区分大小写。

答案 1 :(得分:0)

这个最小的例子对我来说在0.86.3075.0:

中运行正常

在此示例中,a.build和b.build都多次包含c.build。 a.build和b.build也包含彼此,但不依赖于彼此的目标,因为这会产生循环依赖。

请注意在项目级别使用echo - 这些似乎是在包含文件时出现的,这可能有助于您调试问题。

a.build:

<?xml version="1.0" encoding="utf-8"?>
<project default="a.go" name="a">

    <echo message="In A"/>

    <include buildfile="b.build" />
    <include buildfile="b.build" />
    <include buildfile="c.build" />
    <include buildfile="c.build" />

    <target name="a.go" depends="c.go">
        <echo message="Building A"/>
    </target>

    <include buildfile="b.build" />
    <include buildfile="c.build" />

</project>

b.build:

<?xml version="1.0" encoding="utf-8"?>
<project default="b.go" name="b">

    <echo message="In B"/>

    <include buildfile="a.build" />
    <include buildfile="a.build" />
    <include buildfile="c.build" />
    <include buildfile="c.build" />

    <target name="b.go" depends="c.go">
        <echo message="Building B"/>
    </target>

    <include buildfile="a.build" />
    <include buildfile="c.build" />

</project>

c.build:

<?xml version="1.0" encoding="utf-8"?>
<project default="c.go" name="c">

    <echo message="In C"/>

    <target name="c.go">
        <echo message="Building C"/>
    </target>

</project>

输出:

NAnt 0.86 (Build 0.86.3075.0; nightly; 02/06/2008)
Copyright (C) 2001-2008 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/Documents and Settings/rbaker/My Documents/nantinclude/a.build
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: a.go 

     [echo] In A
     [echo] In B
     [echo] In C

c.go:

     [echo] Building C

a.go:

     [echo] Building A

BUILD SUCCEEDED

Total time: 0.1 seconds.

NAnt 0.86 (Build 0.86.3075.0; nightly; 02/06/2008)
Copyright (C) 2001-2008 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/Documents and Settings/rbaker/My Documents/nantinclude/b.build
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: b.go 

     [echo] In B
     [echo] In A
     [echo] In C

c.go:

     [echo] Building C

b.go:

     [echo] Building B

BUILD SUCCEEDED

Total time: 0.1 seconds.

NAnt 0.86 (Build 0.86.3075.0; nightly; 02/06/2008)
Copyright (C) 2001-2008 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/Documents and Settings/rbaker/My Documents/nantinclude/c.build
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: c.go 

     [echo] In C

c.go:

     [echo] Building C

BUILD SUCCEEDED

Total time: 0 seconds.