Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace web config *elements* with msdeploy parameters

Tags:

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?

like image 302
Lars Andreas Ek Avatar asked Jul 15 '10 16:07

Lars Andreas Ek


People also ask

What is DeployOnBuild?

The DeployOnBuild=true property essentially means "I want to execute an additional target when build completes successfully." The DeployTarget property identifies the name of the target you want to execute when the DeployOnBuild property is equal to true.

What is SetParameters XML?

SetParameters. xml file. This provides a set of parameter values to the MSDeploy.exe command. You can update the values in this file and pass it to Web Deploy as a command-line parameter when you deploy your web package.

Where is web config file in Visual Studio 2022?

config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ folder. The default settings that are contained in the Machine.

How do I open web config file in Visual Studio?

In Solution Explorer, right-click your Web site name, and then click Add New Item. In the Templates window, click Web Configuration File. The file name in the Name text box should be Web. config.


1 Answers

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> 
like image 110
Dave Avatar answered Sep 17 '22 20:09

Dave