Search code examples
pathincludedirectorynant

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


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.


Solution

  • 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)}