Sign in to follow this  
Quat

[.net] visual studio working directory

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this