NAnt - how to get the directory path of the included script

99封情书 提交于 2019-12-24 05:14:10

问题


I have a common NAnt script (containing some common targets and constants) that I include in many other NAnt scripts like this:

<include buildfile="<path>\common.build" verbose="true" />

Calling scripts are in various folders.

In this included script I need to read a file from the same directory, where included script resides. "Current directory" is set to the directory of the calling script, not included one. How can I get the directory path of the included script?

If I use the following construct (inside included script):

${ path::get-directory-name(project::get-buildfile-path()) }

then I get the folder path of the calling script, rather than of the included script.

Is there any way to get the path of the included script inside it?

Regards, Ivan.


回答1:


My suggestion: Define the path to the called script file in a property inside the calling script like this:

<property name="include.buildfile.path" value="C:\foo\common.build" />
<include buildfile="${include.buildfile.path}" verbose="true" />

I the common script you access the desired directory path like this:

${path::get-directory-name(include.buildfile.path)}



回答2:


I had a look at NAnt source code, unfortunately what you want to achieve is not doable with an existing or custom function - NAnt appends the included file into it's project structure, and while Project has a LocationMap to get back the filename from which a certain node came, it's marked as internal, so can't even get extracted with a script. You can either go for a workaround, like assuming a constant location of your file in relation to the master script (and walk down from there) or build a custom version of NAnt with a function exposing the functionality you need. First solution is not pretty, second one is not easy.



来源:https://stackoverflow.com/questions/12408020/nant-how-to-get-the-directory-path-of-the-included-script

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