When we deploy applications, there is usually a separate machine for production and development. Most of the applications have settings in a regular .NET App.config
or Web.config
file. For example:
<add key="Dev_Setting1" value="val1"/>
<add key="Prod_Setting1" value="val2"/>
<add key="Prod_Setting1" value="val3"/>
<add key="Prod_Setting2" value="val4"/>
We'd like to have the applications choose automatically between two sets of settings, depending on the machine. Is there a standard way of doing this? Other suggestions welcome.
How about the following approach?
Having the machine name in one of the settings would allow you to determine which prefix needs to be used to load up the application settings - so long as you avoid loading through the standard API and instead implement your own 'get me a setting value' you can lookup the setting prefix from the machine name and then look up the relevant setting.
I usually use a method that first looks for a setting with the machine name as prefix:
That way you can have a default setting, and local settings for any machine: