Replace web config *elements* with msdeploy parameters
Asked Answered
J

1

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?

Jenness answered 15/7, 2010 at 16:51 Comment(0)
D
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>
Daloris answered 22/12, 2010 at 5:19 Comment(6)
Worked for me --- the /text() is what I was missing. Not an xpath pro. This should be marked as the answer. Thanks Dave.Dipody
Agree with @Dipody - this should be marked as the correct answer.Trig
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.Brachypterous
It's right! It didn't work with Microsoft Web Deploy V3Deterrent
If you call v3 with -verbose you can see it can't match based on /text() for some reason...Ecliptic
Not sure if this a v3 thing, or even relevant, but I just had a confusing situation where /text() was failing and later discovered it was due to a namespace mismatch as per here: #5830796Pacemaker

© 2022 - 2024 — McMap. All rights reserved.