How to migrate web.config?
<p><strong>situation</strong></p>

<p>We use migrations to update the database schema and configuration files for all deployments of our web application. Now we have a problem with migrating the web.config.</p>

<p><strong>current implementation</strong></p>

<p>The migration process does the following:</p>

<ol>
<li>Open the database connection</li>
<li>Read configuration from web.config into a configuration object</li>
<li>Retrieve all migrations</li>
<li>Iterate migrations 
<ol>
<li>Update database schema (database connection is passed as parameter)</li>
<li>Update configuration object (configuration object is passed as parameter)</li>
</ol></li>
<li>Save configuration object</li>
<li>Close database connection</li>
</ol>

<p>Of course there is a lot of code that makes sure that the migrations are not screwing things up when something goes wrong. No worries there. Also restarting the webserver upon save the configuration is not a problem either.</p>

<p><strong>problem</strong></p>

<p>The problem is that it does not seem possible to make certain changes to the web.config through the configuration object. Like adding a location.</p>

<p><strong>possible solution</strong></p>

<p>My thoughts are now to not pass the configuration object, but the *.config files as a dictionary of xml documents. The migrations can then make changes to the raw xml. </p>

<p><strong>worries</strong></p>

<p>I am not too exited about this approach, because the configuration object does some configuration data integrity checks. This capability is lost when working with raw xml.</p>

<p><strong>question</strong></p>

<p>Is this the best approach?</p>
