在 Visual Studio 中调试时如何更改工作目录?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在项目属性中,打开调试选项卡。 在那里,您会找到一个用于更改工作目录的文本框。
In the project properties, open the debug tab. In there, you will find a textbox to change the working directory.
在项目上设置构建后事件,以将配置文件移动到调试构建目录中。
右键单击需要其他项目配置的项目并选择属性,单击构建事件选项卡,然后添加构建后事件。 像这样的事情:
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:
我通过转到项目属性编译选项卡并更改构建输出路径解决了这个问题。 希望这对你有用。
我相信当您准备好进行发布构建时,您需要将其更改回 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.
它写回同一个旧文件夹的原因可能是管理权限。
The reason, why it writes back to the same old folder may be administration rights.