I have a windows form project in Visual Studio that reads configuration files from an other 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 "/Project1/connection.config".
我在Visual Studio中有一个Windows窗体项目,它从同一解决方案中的其他项目中读取配置文件。部署后,此应用程序将从解决方案的根文件夹运行,然后将从“/Project1/connection.config”等内容中读取文件。
When I however debug the 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.
然而,当我调试表单应用程序并获得正在执行的程序集路径时,它将从“bin / Debug”或“bin / Release”运行,因为配置文件的路径不同。
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?
有没有办法告诉Visual Studio从不同的路径调试应用程序,或者只是在编译后复制应用程序,并从部署后运行的同一路径调试/运行它?
4 个解决方案
#1
Set a post build event on your project to move the config file into the debug build directory.
在项目上设置post build事件,将配置文件移动到debug build目录中。
Right click on the project that will require the config from a different project and select properties, then click on the build events tab and add a post build event something like this:
右键单击需要来自不同项目的配置并选择属性的项目,然后单击构建事件选项卡并添加如下所示的构建后事件:
Copy configFilePath $(TargetPath)
复制configFilePath $(TargetPath)
#2
In the project properties, open the debug tab. In there, you will find a textbox to change the working directory.
在项目属性中,打开调试选项卡。在那里,您将找到一个文本框来更改工作目录。
#3
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.
我相信当你准备好发布版本时,你需要将它改回bin \。
#4
The reason, why it writes back to the same old folder may be administration rights.
原因是,为什么它写回同一个旧文件夹可能是管理权限。
#1
Set a post build event on your project to move the config file into the debug build directory.
在项目上设置post build事件,将配置文件移动到debug build目录中。
Right click on the project that will require the config from a different project and select properties, then click on the build events tab and add a post build event something like this:
右键单击需要来自不同项目的配置并选择属性的项目,然后单击构建事件选项卡并添加如下所示的构建后事件:
Copy configFilePath $(TargetPath)
复制configFilePath $(TargetPath)
#2
In the project properties, open the debug tab. In there, you will find a textbox to change the working directory.
在项目属性中,打开调试选项卡。在那里,您将找到一个文本框来更改工作目录。
#3
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.
我相信当你准备好发布版本时,你需要将它改回bin \。
#4
The reason, why it writes back to the same old folder may be administration rights.
原因是,为什么它写回同一个旧文件夹可能是管理权限。