views:

28

answers:

1

I'm currently working with systems that has quite a lot of configuration settings that are environment specific (Dev, UAT, Production). Does anyone have any suggestions for minimizing the changes needed to the config file when moving between environments as well as minimizing the duplication of data in the config file?

It's mostly Application settings rather than User settings.

The way I'm doing it at the moment is something similar to this:

<DevConnectionString>xyz</DevConnectionString>
<DevInboundPath>xyz</DevInboundPath>
<DevProcessedPath>xyz</DevProcessedPath>
<UatConnectionString>xyz</UatConnectionString>
<UatInboundPath>xyz</UatInboundPath>
<UatProcessedPath>xyz</UatProcessedPath>
...
<Environment>Dev</Environment>

And then I have a class that reads in the Environment setting via the My.Settings class (it's VB project) and then uses that to decide what other settings to retrieve. This leads to too much duplication though so I'm not sure if it's worth it.

+1  A: 

Why not have the environment define the configuration file to read, then have that file keyed without the prefixes? That way, you can parse the different configurations with the same code.

my.settings: Read this to figure out what settings file to use.

<EnvironmentMapping>
    <Environment>Dev</Environment>
    <File>dev.settings</File>
</EnvironmentMapping>
<EnvironmentMapping>
    <Environment>Uat</Environment>
    <File>uat.settings</File>
</EnvironmentMapping>
<Environment>Dev</Environment>

dev.settings: These are the settings for the Dev environment. This is only read if Dev is the selected environment.

<ConnectionString>devconnection</ConnectionString>
<InboundPath>devinbound</InboundPath>
<ProcessedPath>devprocessed</ProcessedPath>

uat.settings: These are the settings for the UAT environment. This is only read if Uat is the selected environment.

<ConnectionString>uatconnection</ConnectionString>
<InboundPath>uatinbound</InboundPath>
<ProcessedPath>uatprocessed</ProcessedPath>
jdmichal
An interesting alternative, thank you.
ho1