Development vs. Production: Application.StartingPath

  • Thread starter Thread starter Axe
  • Start date Start date
A

Axe

I've got a C# winform application I'm developing where I'm heavily reliant
on certain keys in the app.config file. I understand that when I build and
run the app in VS.NET app.config is rebuilt (?) and renamed as
MyApp.exe.config and placed next to the executable file. However, this
config file is stuck in the bin/debug or bin/release directories while all
of the other directories required reside two levels up from there. When I
deploy this application we will be putting the executable at the same level
as the other directories (there will be no bin, etc.).

So the problem is I'd like to get rid of some of these keys in my
appSettings section of the config file but I can't refer to them using
Application.StartingPath or Application.ExecutionPath since they are two
levels down when I'm developing this thing. I can't very well just go
through and change them just prior to releasing as my application will be
tested thouroughly.

What gives? What can I do here? I'd like to stop relying on the config
file for all of my required paths.

Axe
 
Try using the Registry! Or alternatively, create a Windows
Service that has its own configuration entries and can
deliver the required info to you when requested. This
works well at an enterprise level where changing a setting
has an effect (optionally) on all the clients.
 
Eeeeuuuwwwww!

Two ideas:

1) Have your installer generate the app config file, to point to wherever
the program is installed, or
2) Use relative paths (relative to the exe), and search upwards for the
required directory.
 
Axe,
In addition to Stu's & Jon's suggestions.
appSettings section of the config file but I can't refer to them using
Application.StartingPath or Application.ExecutionPath since they are two
levels down when I'm developing this thing.
Have you considered moving "them" two levels up during development?

Another option may be to change the Working Directory (under Project
Properties - Configuration Properties - Debugging) to be your project root,
then base "them" on the current directory and not StartingPath or
ExecutionPath.

A third option may be to change the Output Path under Project Properties -
Configuration Properties - Build to be the level you expect.

A fourth alternative (which I don't really care for) is to check the
System.Diagnostics.Debugger.IsAttached property to see if you are running in
VS.NET and change the paths appropriately...

A fifth option is to have separate configuration sections in your app
config, one for development and one for production. This is handy if you
have separate environments for each 'stage' (development, QA, production)
and you need to keep printers, databases, message queues, SMTP servers and
other resources separated between each environments.

Hope this helps
Jay
 
Back
Top