Using MSDeploy to update and remove sections in web.config. A simple example

I got a case the other day where customer was using Microsoft Web Deploy 3.0.


“Web Deploy 3.0”


There were 3 questions around this.

. How to change the value of some settings for their site in the web.config.

. How to remove or delete a whole section in the web.config.

. How to do this using the –setParamFile argument.


This post shows how to do this in a step by step fashion. The assumption is of course that Web Deploy is installed.

This should be at: C:\Program Files\IIS\Microsoft Web Deploy V3\


Rather than using two IIS instances, I will just use two directories. One to be the Source and one to be the Destination.


#1 Create a Src directory: C:\WebDeployDemo\Src

#2 Create a Dst directory: C:\WebDeployDemo\Dst

#3 Create a web.config in both Src and Dst directories, i.e.:






#4 Set the content of both the web.config files to be:




                         <site description=”someDescriptionsiteId=”someId“>

                                     <siteSettings aBooleanSetting=”False” aStringSetting=”someStringValue“/>




                         <add value=”someValue1″ enabled=”False”/>

                         <add value=”someValue2″ enabled=”True”/>




#5 Create a parameter file (to be used by the –setParamFile argument) called ParameterFile.xml in the C:\WebDeployDemo directory, i.e.:




Set the content to:



            <parameter name=”changeBool” value=”True”>

                         <parameterEntry type=”XMLFile” scope=”web.config$” match=”//configuration/sites/site/siteSettings/@aBooleanSetting”/>


            <parameter name=”changeString” value=”aNewAndChangedValue“>

                         <parameterEntry type=”XMLFile” scope=”web.config$” match=”//configuration/sites/site/siteSettings/@aStringSetting”/>


            <parameter name=”removeSection” value=””>

                         <parameterValidation kind=”AllowEmpty” />

                         <parameterEntry type=”XMLFile” scope=”web.config$” match=”//configuration/customSection“/>




The above file will do the following:

. Change the “aBooleanSetting” to TRUE in the destination.

. Change the “aStringSetting” to “aNewAndChangedValue” in the destination.

. Remove the “customSection” section all together in the destination.


#6 Open a command prompt and navigate to C:\Program Files\IIS\Microsoft Web Deploy V3\

#7 Run the following command to execute the changes using the parameters file we just created:


msdeployverb:syncsource:dirpath=C:\WebDeployDemo\Src –dest:dirpath=C:\WebDeployDemo\Dst –setParamFile=C:\WebDeployDemo\ParameterFile.xml


#8 Check the web.config in the Dst folder, it should now be:




                         <site description=”someDescriptionsiteId=”someId“>

                                     <siteSettings aBooleanSetting=”True” aStringSetting=”aNewAndChangedValue” />





And there you go 🙂


NOTE: The above parameter in the ParameterFile.xml will remove the <customSection> section all together.

If you would like to keep the section and but remove all entries, in other words to have the web.config look as follows:




                         <site description=”someDescriptionsiteId=”someId“>

                                     <siteSettings aBooleanSetting=”True” aStringSetting=”aNewAndChangedValue” />








Then you can use a wildcard in the ParameterFile.xml like so:


            <parameter name=”removeSection” value=””>

                         <parameterValidation kind=”AllowEmpty” />

                         <parameterEntry type=”XMLFile” scope=”web.config$” match=”//configuration/customSection//*”/>



Some references:


“Web Deploy Operation Settings”  

“Using declareParam and setParam   




Comments (3)

  1. Sabari says:

    Hi Michael,

    I have a web deployment package which contains the below files.




    I am using octopus tool to deploy the web application in multiple servers.

    Problem: Can i pass configurable parameters from octopus (i mean parameters for web.config to update some keys) to Deployment package to WebApplication.deploy.cmd. If yes, How can i pass the parameters to update my web.config file. Any help in this regard would be great.



  2. Richard Szalay says:

    FYI, the "type" attribute on "parameterEntry" should be "kind".

  3. Carl says:


    Thanks for this, It works really well. One question I have is regarding that custom section. I want to update a web.config file, however I want to keep a section of the web.config on the destination, but replace everything else.

    For example I have a section in my web.config as below.


       <add key="LookupCacheExpiration" value=""/>

       <add key="MainPrimaryColour" value=""/>

       <add key="MainBackgroundColour" value=""/>

       <add key="MainWindowColour" value=""/>

       <add key="MainWindowBorderBrushColour" value=""/>

       <add key="CacheUser" value=""/>

       <add key="CacheHash" value=""/>

       <add key="SessionServer" value=""/>

       <add key="ApplicationServer" value=""/>

       <add key="LogoFileName" value=""/>

       <add key="LogoAlignment" value=""/>

       <add key="CrystalViewer" value=""/>

       <add key="ExclusionsOnline" value=""/>


    I don't want to overwrite this section on my destination, I want it to keep the values it has, but sometimes the rest of the web.config file changes. Is there a way for me to use a wildcard to exclude everything between appSettings, but replace everything else in the web.config with the source file?

    Many thanks