在Visual Studio中调试时如何更改工作目录? [英] How do I change the working directory while debugging in Visual Studio?

查看:583
本文介绍了在Visual Studio中调试时如何更改工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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".

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

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.

是否有一种方法可以告诉Visual Studio从其他路径调试应用程序,或者只是在编译后复制应用程序,然后从与将要运行一次的路径相同的路径调试/运行它

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?

推荐答案

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

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)

这篇关于在Visual Studio中调试时如何更改工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆