Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Our proj has the same issue where we had to maintain configs for dev, qa, uat and prod. Here is what we followed (only applies if you are familiar with MSBuild):</p> <p>Use MSBuild with the MSBuild Community tasks extension. It includes the 'XmlMassUpdate' task that can 'mass-update' entries in any XML file once you give it the correct node to start with.</p> <p>To Implement:</p> <p>1) You need to have one config file which will have your dev env entries; this is the config file in your solution.</p> <p>2) You need to have a 'Substitutions.xml' file, that contains only the entries that are DIFFERENT (appSettings and ConnectionStrings mostly) for each environment. Entries that do not change across environment need not be put in this file. They can live in the web.config file of the solution and will not be touched by the task</p> <p>3) In your build file, just call the XML mass update task and provide the right environment as a parameter. </p> <p>See example below:</p> <pre><code> &lt;!-- Actual Config File --&gt; &lt;appSettings&gt; &lt;add key="ApplicationName" value="NameInDev"/&gt; &lt;add key="ThisDoesNotChange" value="Do not put in substitution file" /&gt; &lt;/appSettings&gt; &lt;!-- Substitutions.xml --&gt; &lt;configuration xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate"&gt; &lt;substitutions&gt; &lt;QA&gt; &lt;appSettings&gt; &lt;add xmu:key="key" key="ApplicationName" value="NameInQA"/&gt; &lt;/appSettings&gt; &lt;/QA&gt; &lt;Prod&gt; &lt;appSettings&gt; &lt;add xmu:key="key" key="ApplicationName" value="NameInProd"/&gt; &lt;/appSettings&gt; &lt;/Prod&gt; &lt;/substitutions&gt; &lt;/configuration&gt; &lt;!-- Build.xml file--&gt; &lt;Target Name="UpdateConfigSections"&gt; &lt;XmlMassUpdate ContentFile="Path\of\copy\of\latest web.config" SubstitutionsFile="path\of\substitutionFile" ContentRoot="/configuration" SubstitutionsRoot="/configuration/substitutions/$(Environment)" /&gt; &lt;/Target&gt; </code></pre> <p>replace '$Environment' with 'QA' or 'Prod' based on what env. you are building for. Note that you should work on a copy of a config file and not the actual config file itself to avoid any possible non-recoverable mistakes.</p> <p>Just run the build file and then move the updated config file to your deployment environment and you are done!</p> <p>For a better overview, read this:</p> <p><a href="http://blogs.microsoft.co.il/blogs/dorony/archive/2008/01/18/easy-configuration-deployment-with-msbuild-and-the-xmlmassupdate-task.aspx" rel="nofollow noreferrer">http://blogs.microsoft.co.il/blogs/dorony/archive/2008/01/18/easy-configuration-deployment-with-msbuild-and-the-xmlmassupdate-task.aspx</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload