When you using MSdeploy you should create a parameters.xml file that exposes your web.config settings at the time of installation. This enables good deployment habits, build the product one and then set system specific values using deployment tools. The problem is that this parameters.xml file is a pain to write, it is a series of XML blocks that contain XPath to find the entries to replace, typo’s are easy to introduce.

A ripe candidate for automation, but I could not find a tool to do it, so I wrote one for Visual Studio 2013 and 2015. You can find the source on GitHub andthe actual VSIX package in the Visual Studio Gallery.

So what does it do?

Once it is installed, if you right click on a web.config file you will see a context menu option to generate a parameters.xml file, click it, if the file does not exist it will be generated and added to the current project. Entries will be made for all appSettings and any custom applicationSettings blocks found in the web.config. The actual web.config values will be replaced with __TAGS__ to be set via Release Management or your tool of choice.

So the web.config file

<configuration>  
  <applicationSettings>  
    <Service.Properties.Settings>  
      <setting name="Directory1" serializeAs="String">  
        <value>C:ABC1111</value>  
      </setting>  
      <setting name="Directory2" serializeAs="String">  
        <value>C:abc2222</value>  
      </setting>  
    </Service.Properties.Settings>  
  </applicationSettings>  
  <appSettings>  
    <add key="APPSETTING1" value="123" />  
    <add key="AppSetting2" value="456" />  
  </appSettings>  
</configuration>   

it generates the parameters.xml

<parameters>  
  <parameter name="APPSETTING1" description="Description for APPSETTING1" defaultvalue="\_\_APPSETTING1\_\_" tags="">  
    <parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add\[@key='APPSETTING1'\]/@value" />  
  </parameter> 

  <parameter name="AppSetting2" description="Description for AppSetting2" defaultvalue="\_\_APPSETTING2\_\_" tags="">  
    <parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add\[@key='AppSetting2'\]/@value" />  
  </parameter>

  <parameter name="Directory1" description="Description for Directory1" defaultvalue="\_\_DIRECTORY1\_\_" tags="">  
    <parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/Service.Properties.Settings/setting\[@name='Directory1'\]/value/text()" />  
  </parameter>

  <parameter name="Directory2" description="Description for Directory2" defaultvalue="\_\_DIRECTORY2\_\_" tags="">  
    <parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/Service.Properties.Settings/setting\[@name='Directory2'\]/value/text()" />  
  </parameter>

</parameters>

If a parameters.xml file already exists then you are prompted first if you wish to replace it, if you say no, then you  are prompted if you wish to add any new entries in the web.config, or do nothing.

All the work is done via an XSL Transform, so if you need to transform extra settings just add to the embedded XSLT resource and rebuild the VSIX package.

So the tool won’t do everything, but should get you close to the file you need.