How do I change the working directory while debugging in Visual Studio?
Asked Answered
F

4

13

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?

Furness answered 9/7, 2009 at 10:5 Comment(0)
A
2

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)
Allhallows answered 9/7, 2009 at 10:10 Comment(1)
Re "...move the configuration file": Do you mean "...copy the configuration file"?Weil
M
29

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

Monophyletic answered 9/7, 2009 at 10:10 Comment(2)
For some reason this still loads the executing assembly from bin/DebugFurness
@Furness just change the Working directoryLevo
A
2

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)
Allhallows answered 9/7, 2009 at 10:10 Comment(1)
Re "...move the configuration file": Do you mean "...copy the configuration file"?Weil
B
2

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.

Brennan answered 19/10, 2011 at 17:1 Comment(0)
T
1

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

Tafilelt answered 5/2, 2012 at 8:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.