如何在配置文件中设置路径

发布于 2024-09-25 11:49:39 字数 689 浏览 2 评论 0原文

我有一个运行脚本的测试。它从 app.config 文件获取路径:

<scriptsSectionGroup>
    <scriptsCollection>
      <scripts>
        <add name="TestScript" path="C:\My Projects\RestServicePublishing\UtilityFixture\testScript.bat"/>
      </scripts>
    </scriptsCollection>
  </scriptsSectionGroup>

“testScript.bat”位于 UtilityFixture 项目中。它不在子文件夹中。

UtilityFixture

  • testScript.bat

但是,我不想指定此处的完整路径。我想让它在项目“UtilityFixture”中找到“testScript.bat”,无论项目位于哪个目录。假设其他人将其从源代码管理下载到其他位置。

为了进一步解释这一点,如果我说将“RestServicePublishing 解决方案移动到一个新文件夹(例如“C:\My Projects 2”),我希望找到该文件。

有人可以告诉我这是否可能吗?

谢谢

I have a test which runs a script. It gets the path from the app.config file:

<scriptsSectionGroup>
    <scriptsCollection>
      <scripts>
        <add name="TestScript" path="C:\My Projects\RestServicePublishing\UtilityFixture\testScript.bat"/>
      </scripts>
    </scriptsCollection>
  </scriptsSectionGroup>

'testScript.bat' is located in the UtilityFixture project. It is not in a subfolder.

UtilityFixture

  • testScript.bat

However I don't want to specify the full path as I have here. I want to make it so that it will find 'testScript.bat' in the project 'UtilityFixture' regardless of what directory the project is sitting it. Say if someone else downloads it from source control to a different location.

To explain this further I want the file to be found if I say moved the 'RestServicePublishing solution to a new folder say "C:\My Projects 2".

Can someone tell me if it is possible?

Thanks

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

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

发布评论

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

评论(1

霊感 2024-10-02 11:49:39

如果脚本与可执行文件位于同一文件夹中,则根本不需要指定路径。否则,您可以相对于 EXE 指定它,

..\testScript.bat            # in parent folder
scripts\testScript.bat       # in subfolder

无论如何,您是对的,您当然不想使用“众所周知”的位置(即硬编码路径)。

You don't need to specify a path at all if the script is in the same folder as the executable. Otherwise, you can specify it relative to the EXE,

..\testScript.bat            # in parent folder
scripts\testScript.bat       # in subfolder

In any case, you're right, you certainly don't want to use a "well-known" location (i.e. hardcoded path).

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