3

I have two applications that have many common configuration properties. When a configuration property of one changes, I want the other to change as well. Does anyone have a sensible way to accomplish this before I start off down the wrong track?

EDIT: I'm using .NET 2.0

probably at the beach
  • 14,489
  • 16
  • 75
  • 116

3 Answers3

7

You can create and reference a common configSource for the configuration section(s) involved. For instance, if you wanted a common set of AppSettings, copy your current appSettings to a new file (say appSettings.shared.config) and replace them in both app configs with this:

<appSettings configSource="appSettings.shared.config"/>

Here's more documentation: http://sunali.com/2008/01/23/configsource-property-dividing-configuration-files-into-pieces/

Far as I know, this cannot be done for an entire file, only sections, and each section will need its own file (and the section must still be declared in the configurationsections element of the app.config). But, this has a number of really cool uses; for instance, you can separate your connection strings into files geared towards different environments (local, development, testing, staging, production) and by changing one filename in one place you've now pointed your app at the different environment.

KeithS
  • 70,210
  • 21
  • 112
  • 164
  • This can also be done for connection strings `` Just a note is that you cannot mix the 2 having some of the settings in the Parent file and some in the shared – Lord Darth Vader Dec 20 '17 at 08:33
6

One easy way to accomplish this is to use the configSource attribute in the app.config in both applications, and point this to a common file. Bingo, change one file, all apps are updated.

Check the MSDN documentation on it here.

Lord Darth Vader
  • 1,895
  • 1
  • 17
  • 26
Kilanash
  • 4,479
  • 1
  • 14
  • 11
3

there are a couple of different ways you could do this:

  1. use the registry
  2. use a config file in a common location
  3. use a configuration table in a database
Muad'Dib
  • 28,542
  • 5
  • 55
  • 68
  • Are you sure you can have two applications sharing a configuration file in a common location? I should have pointed out I'm running .NET 2.0 - I haven't found a way to configure and application to use a custom configuration file. – probably at the beach Mar 04 '11 at 15:57
  • 1
    @richard, you can do this, you just have to load the config file manually. see [this SO question](http://stackoverflow.com/questions/1049868/how-to-load-config-file-programmatically). – Muad'Dib Mar 04 '11 at 16:04