Context Sensitive Config Files

M. Keith Warren was asking for an enhancement to the web.config to look like:

<configuration Name=”Release”>
    <system.web>
 …
   
</system.web>
</configuration>
<configuration Name
=”Debug”>
    <system.web>
 …
   
</system.web>
</configuration>

We solved a similar problem for all config files by creating a wrapper around AppSetting and ConfigurationSettings that looked at various things (machine name, database server, ...) to determine the environment and use the correct settings. I.e.

<appSettings>
     <add key="logging-level" value="debug" />
</appSettings>

<test-environment>
     <add key="logging-level" value="verbose" />
</test-environment>

<prod-environment>
    <add key="logging-level" value="brief" />
</prod-environment>  

This demonstrates also the cascading feature, if the environment is not specified the setting in appSettings is used, this way common settings don't have to be repeated.

Published Wednesday, September 17, 2003 10:55 AM by iclemartin
Filed under:

Comments

# re: Context Sensitive Config Files

Good suggestion but I would like to extend further than just the appSettings node. I am working on an post build component to do this but that does VB.NET people no good.

Wednesday, September 17, 2003 2:10 PM by M. Keith Warren

# re: Context Sensitive Config Files

Just came across this while wandering about the internet, if your using any source control it'd look like a good alternative to the problem.

http://www.bistrotech.net/weblog/default.aspx?date=2003-09-29

Regards,

Alan

Wednesday, October 08, 2003 1:33 PM by Alan

# re: Context Sensitive Config Files

Great solution and good reference, thanks Alan.

Wednesday, October 08, 2003 3:07 PM by Wayne Allen

Leave a Comment

(required) 
(required) 
(optional)
(required)