Nant:无法从 .include 获取当前目录

发布于 2024-10-29 07:32:17 字数 598 浏览 4 评论 0原文

对我来说总结这一点并不容易......我在磁盘上有这样的结构:

[dir] project

  • [dir] foo
    • [文件] foo.build
  • [目录] bar
    • [文件] bar.build
  • [file] default.include

文件default.include 包含几个属性,它们是构建期间使用的目录。例如: 属性名称=“build.dir”值=“${directory::get-current-directory}”。

default.include 文件由 foo.build 和 bar.build 使用其相对路径包含: include buildfile="..\default.include"

现在的问题是:当我从project\foo dir 运行foo.build 时,我得到了错误的build.dir 值。我需要“project”,但我得到“project\foo”。有没有办法获取 .include 文件所在的目录?

我可以使用 %~dp0 在批处理文件中执行此操作

It's not exactly easy for me to summarize this... I have this structure on disk:

[dir] project

  • [dir] foo
    • [file] foo.build
  • [dir] bar
    • [file] bar.build
  • [file] default.include

The file default.include contains a couple of properties which are the directories used during the build. E.g:
property name="build.dir" value="${directory::get-current-directory}".

The default.include file is included by foo.build and bar.build using its relative path:
include buildfile="..\default.include"

Now the problem: when I run foo.build from project\foo dir, I get the wrong value for build.dir. I need "project" and I get "project\foo" instead. Is there a way to get the directory in which the .include file exists?

I could do this in a batch file using %~dp0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟酉 2024-11-05 07:32:17

您可以使用它指定项目的基目录

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

,并确保将构建输出路径设置为 build.dir

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

国际总奸 2024-11-05 07:32:17

在包含共享包含内容之前,您可以将构建路径属性设置为工作文件夹和项目根目录之间的相对差异。所以,在 \project\foo\foo.build 中:

>
>

如果您想引用与项目根目录相关的内容,则只需从 build.dir 构建路径即可。假设您有一个 \project\utilities\ 文件夹,其中放置了一些自定义构建工具或其他东西,那么您可以将该文件夹引用为:


utils.dir 将为 ..\utilities\ ,这将是工作文件夹中的正确值(在本例中为 \project\foo\ )。

就我个人而言,我以相反的方式做事 - 我在项目的根目录中有主构建文件,它包含每个子项目的构建文件。从物理上讲,构建分布在各个项目中,但从逻辑上讲,它的运行就像项目根目录中的一个大脚本一样。缺点是全局属性名称和目标名称可能会发生冲突,因此您需要命名约定来防止这种情况发生。

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.

尤怨 2024-11-05 07:32:17

刚刚遇到了完全相同的问题:
NAnt - 如何获取包含脚本

在我的包含文件中,我需要获取包含文件的目录,以引用与其相关的其他内容。
似乎当 NAnt 包含另一个构建文件时,它包含它的内容,而不更改其环境中的任何内容(directory::get-current-directory、project::get-buildfile-path 等)。

您的情况的另一个解决方案可能是使用 任务而不是 。显然,如果您不需要从包含的脚本返回任何内容而只想运行它,那么它就可以工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文