Detecting bin\debug versus bin\release?

A

AdamM

How can an app detect whether its running under debug or release mode and update file paths automatically?
I have several hardcoded paths like "c:\app\bin\debug" currently and want to make it more robust.

Thanks!

Adam
 
P

Peter Rilling

Why are you hardcoding the paths to begin with?

If you need to detect that, I would imaging that you could use the #if DEBUG and set a variable according to what you are running in.

How can an app detect whether its running under debug or release mode and update file paths automatically?
I have several hardcoded paths like "c:\app\bin\debug" currently and want to make it more robust.

Thanks!

Adam
 
A

Andreas Mueller

AdamM said:
How can an app detect whether its running under debug or release mode
and update file paths automatically?
I have several hardcoded paths like "c:\app\bin\debug" currently and
want to make it more robust.

Thanks!

Adam
Hi Adam,

use Application.StartupPath to determine the directory. Now there are
two ways (Well, actually there are some more :) ) to handle the paths:

->Make all you hardcoded paths relative to your application directory,
e.g.: ..\..\Data. Use Path.Combine to build a valid Path when you need it.

string path =
Path.GetFullPath(Path.Combine(
Application.StartupPath, @"..\..\Data")
);

->store all you data under thhe current or the all user profile. You can
get the path like this:

string curUserProfile =
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string allUserProfile =
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);


You might want to evaluate to use the isolated storage mechanims, too.

HTH,
Andy
 
N

Nick Hounsome

How can an app detect whether its running under debug or release mode and
update file paths automatically?
I have several hardcoded paths like "c:\app\bin\debug" currently and want to
make it more robust.

Don't do it.

When you release the app to users it will be running under somewhere else
entirely whether it is the debug or the release version.

Use stuff like Application.StartupPath and Environment.SpecialFolder... to
get directories and #if DEBUG or better yet [ConditionalAttribute("DEBUG")]
to perform do debug/release specific stuff or filenames.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top