[.net] visual studio working directory

Started by
1 comment, last by Flimflam 16 years, 2 months ago
I have a solution that contains a custom control project and a C# form project. The C# form project uses the control. The control accesses a data file in its constructor. This causes a couple of things: 1. The form designer seeks to like to execute the control constructor. When this is done, it likes to look for the data file in the root solution directory. 2. When I run the form program, it likes to look for the data file in the Debug or Release folder where the EXE is. So the problem is that I am duplicating the data file in each of these directories, which makes it a pain to update. How is this supposed to be done?
-----Quat
Advertisement
The correct behavious is that the data files should be in the application's working directory (Which I assume you're aware of because of the title of this thread). In C++ and VC2005 (I don't know about C#) you can change it in Visual Studio by going to Project Settings -> Configuration Properties -> Debugging -> Working Directory, and setting it to $(TargetDir) (Which is the macro that refers to the output directory).
Quote:Original post by Quat
I have a solution that contains a custom control project and a C# form project. The C# form project uses the control.

The control accesses a data file in its constructor. This causes a couple of things:

1. The form designer seeks to like to execute the control constructor. When this is done, it likes to look for the data file in the root solution directory.

2. When I run the form program, it likes to look for the data file in the Debug or Release folder where the EXE is.

So the problem is that I am duplicating the data file in each of these directories, which makes it a pain to update. How is this supposed to be done?



Your best bet is to create a directory in your solution directory named something like "Data". Go into your project options. Configuration Properties -> Debugging -> Working Directory, and set it to "$(SolutionDir)/Data" or something like that. Now every time you run the program from the IDE, it will look in that directory for the file, and you can keep all your resources in there until you are ready to distribute, in which case you would use the files normally.

This topic is closed to new replies.

Advertisement