MSDeploy Parameters.xml can only replace web.config values is a value is already set

If you are using a parameters.xml file to set value with MSDeploy I have just found a gotcha. You need some value in the web.config file, not just an empty XML tag, else the replacement fails. So to explain…

I had the following parameters.xml file, and use Release Management to replace the __TAG__ values at deployment time.

<parameters>
  <parameter name="Domain" description="Please enter the name of the domain" defaultvalue="__Domain__" tags="">
    <parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/Web.Properties.Settings/setting[@name='Domain']/value/text()" />
  </parameter>

  <parameter name="AdminGroups" description="Please enter the name of the admin group" defaultvalue="__AdminGroups__" tags="">
    <parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/Web.Properties.Settings/setting[@name='AdminGroups']/value/text()" />
  </parameter>
</parameters>

If my web.config file (in the MSDeploy package to be transformed) was set to

<applicationSettings>
    <Web.Properties.Settings>
      <setting name="Domain" serializeAs="String">
        <value>Blackmarble</value>
      </setting>
      <setting name="AdminGroups" serializeAs="String">
        <value />
      </setting>
    </BlackMarble.ISS.Expenses.Web.Properties.Settings>
  </applicationSettings>

or

<applicationSettings>
    <Web.Properties.Settings>
      <setting name="Domain" serializeAs="String">
        <value>Blackmarble</value>
      </setting>
      <setting name="AdminGroups" serializeAs="String">
        <value></value>
      </setting>
    </BlackMarble.ISS.Expenses.Web.Properties.Settings>
  </applicationSettings>

only the Domain setting was set.

To get both set I had to have a value for each property, even though they were being reset at deployment.

<applicationSettings>
    <Web.Properties.Settings>
      <setting name="Domain" serializeAs="String">
        <value>DummyDomain</value>
      </setting>
      <setting name="AdminGroups" serializeAs="String">
        <value>DummyAdmins</value>
      </setting>
    </BlackMarble.ISS.Expenses.Web.Properties.Settings>
  </applicationSettings>

Never seen that one before.