NAnt: Check if include file was already included

雨燕双飞 提交于 2020-01-06 19:52:24

问题


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


回答1:


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.




回答2:


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.


来源:https://stackoverflow.com/questions/3932481/nant-check-if-include-file-was-already-included

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!