Nant: can't get current directory from .include

痞子三分冷 提交于 2019-12-06 11:11:39

you can specify the base directory of a project by using this

<property name="build.dir" value="${project::get-base-directory()}">

and make sure you set the build output path to be build.dir

You could set the build path property to be the relative difference between the working folder and the project root before including your shared include stuff. So, in \project\foo\foo.build:

<property name="build.dir" value="..\" />
<include buildfile="..\default.include" />

If you want to then refer to things relative to the project root then just build paths from build.dir. Let's say you had a \project\utilities\ folder where you put some custom build tools or something, then you can refer to that folder as:

<property name="utils.dir" value="${build.dir}utilities\" />

utils.dir would be ..\utilities\ which would be the right value from your working folder (\project\foo\ in this case).

Personally I do things the other way around - I have the main build file at the root of the project and it includes a build file for each sub-project. Physically the build is distributed across the projects, but logically it all runs as if it were one big script in the project root. The downside being that global property names and target names can collide so you need a naming convention to prevent that from happening.

Ivan

Just got exactly the same problem: NAnt - how to get the directory path of the included script

In my include file I need to get the directory of the include file, to refer to something else relative to it. Seems like when NAnt includes another build file, it includes the content of it, without changing anything in its environment (directory::get-current-directory, project::get-buildfile-path, etc).

Another solution in your case might be to use <nant> task instead of <include>. Obviously it works if you don't need anything returned from the included script and just want to run it.

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