XmlPreprocess and conditional web.config wishes
Loren Halvorson wrote about XmlPreprocess. It allows you to add some basic logic and token replacement to XML config files, like ASP.NET web.config files, like this:
<configuration>
<system.web>
<!-- ifdef ${production} -->
<!-- <compilation defaultLanguage="c#" debug="false"/> -->
<!-- else -->
<compilation defaultLanguage="c#" debug="true"/>
<!-- endif -->
</system.web>
</configuration>
It's command line driven, so it can be called from an MSI or other deployment script.
Pretty cool. I sure wish there was some sort of native support for this:
<environmentVariables>
<variable name="connectionString">
<condition type="hostname" match="PRODWEB1,PRODWEB2,PRODWEB3" value="prodsql.domain.com,1433" />
<condition type="hostname" match="QAWEB1,QAWEB2" value="qasql.domain.com,1433" />
<condition type="default" value="(local)" />
</variable>
<variable name="debug">
<condition type="ip" match="127.0.0.1" value="true" />
<condition type="default" value="false" />
</variable>
</environmentVariables>
<configuration>
<appSettings>
<add key="sqlConnection" variable="connectionString" />
</appSettings>
<system.web>
<compilation defaultLanguage="c#" debug="$$default"/>
</system.web>
</configuration>
We use prod.config, qa.config, and dev.config at my work. The web.config points to the correct localized settings:
<appSettings file="relative file name" />
It works, but it's a pain because (1) some settings need to vary between environments that don't go in the appSettings node, and (2) it's a pain to manage all these files.