views:

830

answers:

3

We have a fairly large .NET solution with multiple executable projects (winforms and command line programs). Currently each of these projects has its own app.config that contains connection strings, mail server settings and the like. As you can imagine it's not that convenient to make a change in every app.config file whenever a particular setting needs to be updated.

What do you reckon is the best practice for centralized management of these settings? So far I've thought about two different approaches. The first is using a custom class (or classes) that contains the settings and is serialized into and deserialized from XML. The second approach is defining an app.config file only for a single project and using ConfigurationManager.OpenExeConfiguration() to access it.

+1  A: 

Create the App.config on your startup project and link statically to it on the other projects.

You can link statically by going to Add->Existing Item, and when clicking the Add button on the File Browser Window, there is a small down arrow on the Add button. Click there and the "Add as link" option will be shown. That will place the same App.Config on both projects, with only one actual file.

If your projects have different App.Config with only 'some' settings that are the same, consider checking the file parameter; I mean, you can have more than one App.Config in a project: http://weblogs.asp.net/pwilson/archive/2003/04/09/5261.aspx

Just create a central common.config file and point to it.

Leahn Novash
While this could work when I'm developing and debugging the solution, I'm afraid it wouldn't work once the solution is deployed and a user needs to change the settings.
A: 

Personally I would advise against introducing a needless dependency on a .config file from another assembly. Using a custom class with serializing sounds cleaner in this scenario, but you expose yourself to potential versioning problems and you lose the potential advantages offered by app.config (section handlers, etc.).

+1  A: 

Use the ConfigSource directive to have all of the settings loaded from a central file with the shared values.

technophile