21

We're using msdeploy (or web deploy if you wish) to package and deploy web apps. By declaring parameters package time we can provide values at deploy time (to replace connection strings among other things).

The problem we currently face is replacing values in applicationSettings sections in our web config. We can't get msdeploy to replace the value because the content we want to replace is the text inside an xml element, not an attribute value (the warning we get is: "Cannot set a value on node type 'Element'").

The relevant config looks like this:

<applicationSettings>
  <Name.Of.Assembly.Properties.Settings>
    <setting name="someSetting" serializeAs="String">
      <value>I wanna be replaced</value>
    </setting>
  </Name.Of.Assembly.Properties.Settings>
</applicationSettings>

and the declare parameter xml looks like this:

<parameter name="XX" defaultValue="default">
  <parameterEntry kind="XmlFile"
                       scope="Web\.config$"
                       match="/configuration/applicationSettings/Name.Of.Assembly.Properties.Settings/setting[@name='someSetting']/value" />
</parameter>

Does msdeploy only support replacing attribute values or am I doing something wrong?

1 Answer 1

44

For posterity...

You just need to add "/text()" to the end of the match. That will change the value of enclosed by the tags. However, this value cannot be empty in the source web.config. So when you build the deployment package using the "Release" solution configuration, the web.Release.config must not set this value of the setting to an empty value.

<parameter name="XX" defaultValue="default">
  <parameterEntry kind="XmlFile"
                       scope="Web\.config$"
                       match="/configuration/applicationSettings/Name.Of.Assembly.Properties.Settings/setting[@name='someSetting']/value/text()" />
</parameter>
Sign up to request clarification or add additional context in comments.

6 Comments

Worked for me --- the /text() is what I was missing. Not an xpath pro. This should be marked as the answer. Thanks Dave.
Agree with @TravisWhidden - this should be marked as the correct answer.
Currently trying this with Microsoft Web Deploy V3 which hails as Version 7.1.1764.0. Tried "/configuration/applicationSettings/Name.Of.Assembly.Properties.Settings/setting[@name='someSetting']/value/text()" . The XPath is definitely correct, was verified here: freeformatter.com/xpath-tester.html . But msDeploy simply would not find the setting. It definitely did not work.
It's right! It didn't work with Microsoft Web Deploy V3
If you call v3 with -verbose you can see it can't match based on /text() for some reason...
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.