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

发布于 2024-09-27 14:23:37 字数 228 浏览 8 评论 0原文

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

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

这将引发目标重复的异常。有办法解决吗?

提前致谢

Does anybody know a way to check if a file was already included?

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

This will throw an exception that a target was duplicated. Is there a way around?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别挽留 2024-10-04 14:23:37

刚刚看到这个问题,它似乎相关,并决定更改其中一个重复项的大小写a.build 在我的另一个答案中:

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

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

Just saw this question which seems related and decided to change the case of one of the duplicate includes in a.build in my other answer to:

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

Boom - duplicate target error. Looks like nant is bright enough to ignore duplicate includes, but is case sensitive when comparing them.

不顾 2024-10-04 14:23:37

这个最小的例子在 nant 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.

This minimal example works OK for me in nant 0.86.3075.0:

In this example, a.build and b.build both include c.build multiple times. a.build and b.build also include each other, but do not depend on each other's targets as this creates a circular dependency.

Note the use of echo at project level - these seem to come out as the files are included, which may help you debug your issue.

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>

output:

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文