NAnt: Check if include file was already included

2019-09-09 06:54发布

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

标签: nant
2条回答
劫难
2楼-- · 2019-09-09 06:54

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.

查看更多
何必那么认真
3楼-- · 2019-09-09 06:57

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.
查看更多
登录 后发表回答