在 Visual Studio 中调试时如何更改工作目录?

发布于 2024-07-26 07:30:59 字数 399 浏览 4 评论 0原文

我在 Visual Studio 中有一个 Windows 窗体 项目,它从同一解决方案中的另一个项目读取配置文件。 部署后,该应用程序将从解决方案的根文件夹运行,然后将从“<执行程序集路径>/Project1/connection.config”之类的位置读取文件。

然而,当我调试 Windows 窗体应用程序并获取执行程序集路径时,它将从“bin/Debug”或“bin/Release”运行,因此配置文件的路径不同。

有没有办法告诉 Visual Studio 从不同的路径调试应用程序,或者只是在编译后复制应用程序并从部署后运行的相同路径调试/运行它?

I have a Windows Forms project in Visual Studio that reads configuration files from another project in the same solution. Once deployed, this application will run from the root folder for the solution, and the files will then be read from something like "<Executing assembly path>/Project1/connection.config".

When I however debug the Windows Forms application and get the executing assembly path, it will run from "bin/Debug" or "bin/Release", ergo the path to the configuration files is different.

Is there a way to tell Visual Studio either debug the application from a different path or just copy the application once compiled and debug/run it from the same path as it will be run from once it is deployed?

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

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

发布评论

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

评论(4

拒绝两难 2024-08-02 07:30:59

在项目属性中,打开调试选项卡。 在那里,您会找到一个用于更改工作目录的文本框。

In the project properties, open the debug tab. In there, you will find a textbox to change the working directory.

提赋 2024-08-02 07:30:59

在项目上设置构建后事件,以将配置文件移动到调试构建目录中。

右键单击需要其他项目配置的项目并选择属性,单击构建事件选项卡,然后添加构建后事件。 像这样的事情:

Copy configFilePath $(TargetPath)

Set a post build event on your project to move the configuration file into the debug build directory.

Right click on the project that will require the configuration from a different project and select properties, click on the build events tab, and add a post build event. Something like this:

Copy configFilePath $(TargetPath)
末骤雨初歇 2024-08-02 07:30:59

我通过转到项目属性编译选项卡并更改构建输出路径解决了这个问题。 希望这对你有用。

我相信当您准备好进行发布构建时,您需要将其更改回 bin\ 。

I solved this problem by going to the project properties compile tab, and changing the build output path. Hopefully this will work for you.

I believe you will need to change that back to bin\ when you are ready to do a release build.

临走之时 2024-08-02 07:30:59

它写回同一个旧文件夹的原因可能是管理权限。

The reason, why it writes back to the same old folder may be administration rights.

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