Split application-specific and customer-specific web.config parts
<p>We have a web application running on-premise at a variety of customers. The web.config contains lots of </p>

<ol>
<li>stuff which is "part of our application" (such as most of the <code>&lt;system.web&gt;</code> and <code>&lt;system.webServer&gt;</code> blocks) and </li>
<li>stuff which needs to be customized (connection strings, app settings, and various custom tags).</li>
</ol>

<p>During updates, part 1 should be replaced and part 2 should be left as it is. Ideally, I'd have a <code>web.app.config</code> and a <code>web.custom.config</code>, so I can replace only the first one. Of course, IIS would need to magically "merge" those at run time, which it does not do.</p>

<p>I found the following approaches:</p>

<ul>
<li><p><a href="http://blog.andreloker.de/post/2008/06/keep-your-config-clean-with-external-config-files.aspx" rel="nofollow noreferrer">Put the custom stuff in external files</a>, i.e. <code>&lt;appSettings configSource="appSettings.config"/&gt;</code>.</p>

<p>I cannot use that, because it can only be used for <em>complete sections</em>. But, for example, the <code>aspnet:MaxHttpCollectionKeys</code> setting is a value that <a href="https://stackoverflow.com/questions/13306558/maximum-value-for-aspnetmaxhttpcollectionkeys">should be controlled by the application</a>, whereas other app settings values should be customizable.</p></li>
<li><p><a href="http://vishaljoshi.blogspot.co.at/2010/06/parameterization-vs-webconfig.html" rel="nofollow noreferrer">Parameterization or Web.Config Transformation</a>.</p>

<p>I cannot use that, because our customers have various versions of our application installed. Thus, I need to <em>replace</em> the application-specific parts of web.config rather than transforming individual tags. In addition, I'd like to avoid adding msdeploy to our deployment process (xcopy plus some scripts to create the IIS apps and configure them work great at the moment). Oh, and I'd still have one big web.config with application-specific and customer-specific stuff meshed together.</p></li>
</ul>

<p>Is there some elegant solution that I've missed?</p>