title: Coding transform files for existing web.configs (Reinventing the wheel?)
body: <p>I'm wondering why anyone (including myself) bothers to create insanely long and tedious xdt transforms for each key in a web.config file when one can simply put a "Replace" statement alongside the configuration declaration.</p>
  
  <p>Let me explain with an example:</p>
  
  <p>You are a developer that has been tasked to create a series of web.config transforms for a large web application.</p>
  
  <p>You are given the web.configs for each environment and told to make:</p>
  
  <ul>
  <li>a base web.config that contains all keys and values common to each
  environment</li>
  <li>sets of transform files that contain all keys and values that differ from environment to environment</li>
  </ul>
  
  <p>Here is a sample base web.config:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
  &lt;appSettings&gt;
      &lt;add key="db.schema" value="app" /&gt;
      &lt;add key="versionNumber" value="" /&gt;
      &lt;add key="culture" value="en-US" /&gt;
      &lt;add key="url" value="" /&gt;
      &lt;add key="cache.Duration" value="0" /&gt;
  &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Here is a sample transform for the base web.config:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"&gt;
  &lt;appSettings&gt;
  &lt;add key="versionNumber"
       value="01.67.00"
       xdt:Transform="Replace" xdt:Locator="Match(key)"/&gt;
  &lt;add key="url"
       value="http://thisIsNotAnActualURL.com"
       xdt:Transform="Replace" xdt:Locator="Match(key)" /&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p></p>
  
  <p>Which outputs, as desired, the following:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
  &lt;appSettings&gt;
      &lt;add key="db.schema" value="app" /&gt;
      &lt;add key="versionNumber" value="01.67.00" /&gt;
      &lt;add key="culture" value="en-US" /&gt;
      &lt;add key="url" value="http://thisIsNotAnActualURL.com" /&gt;
      &lt;add key="cache.Duration" value="0" /&gt;
  &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><br>
  <br>
  This is all fair and well but if you're a developer that's creating transforms based on massive web.configs that already exist wouldn't it be a lot easier to do the following as opposed to the above approach:</p>
  
  <p>Base web.config:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Transform:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="Replace"&gt;
  &lt;appSettings&gt;
      &lt;add key="db.schema" value="app" /&gt;
      &lt;add key="versionNumber" value="01.67.00" /&gt;
      &lt;add key="culture" value="en-US" /&gt;
      &lt;add key="url" value="http://thisIsNotAnActualURL.com" /&gt;
      &lt;add key="cache.Duration" value="0" /&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p></p>
  
  <p>The result is identical to the previous example, with far less work involved:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
  &lt;appSettings&gt;
      &lt;add key="db.schema" value="app" /&gt;
      &lt;add key="versionNumber" value="01.67.00" /&gt;
      &lt;add key="culture" value="en-US" /&gt;
      &lt;add key="url" value="http://thisIsNotAnActualURL.com" /&gt;
      &lt;add key="cache.Duration" value="0" /&gt;
  &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I understand that by using this approach, when a change needs to occur in every environment, the change needs to be reflected in every transform; but apart from that, I can't see any drawback.</p>
  
  <p>Please tell me I'm missing something obvious here, as I'm finding transforms that took me over 8 hours to code can be done in a matter of seconds with no apparent drawback</p>