Can I embed elements in web.config using Web Deploy?

Is it possible to insert an XML element into my web.config using Web Deploy Parameters.xml system ?

The XmlFile "view" parameter is closest to what I need, but its match attribute accepts only an XPath request, and I cannot specify a nonexistent element in my XPath request. (Or rather, I can specify a nonexistent element - Web Deploy simply ignores it.) In particular, I would like to convert this:

 <configuration> <plugins> <add name="bleh"/> </plugins> </configuration> 

in it:

 <configuration> <plugins> <add name="bleh"> <option name="foo" value="bar"/> </add> </plugins> </configuration> 

(Unfortunately, I cannot preload web.config with an empty option element because this particular plugin system does not like unrecognized / empty options.)

Thanks for any ideas!

+8
xpath xslt webdeploy msdeploy
source share
4 answers

Xpath is only a query language for XML documents - it alone cannot modify an XML document or create a new XML document .

A language specifically designed to transform an XML document is called XSLT.

Here is a very short and simple XSLT transformation that solves your problem :

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="add[@name='bleh']"> <xsl:copy> <xsl:copy-of select="@*"/> <option name="foo" value="bar"/> </xsl:copy> </xsl:template> </xsl:stylesheet> 

when this conversion is applied to the provided XML document :

 <configuration> <plugins> <add name="bleh"/> </plugins> </configuration> 

required, the correct result is obtained :

 <configuration> <plugins> <add name="bleh"> <option name="foo" value="bar"/> </add> </plugins> </configuration> 
+1
source share

Now these things start with Web Deploy V3. See white paper .

Here is one example parameters.xml file that will add newNode to all nodes, including the root in the target xml file:

 <parameters> <parameter name="Additive" description="Add a node" defaultValue="&lt;newNode />" tags=""> <parameterEntry kind="XmlFile" scope=".*" match="//*" /> </parameter> </parameters> 
+2
source share

Can you just use the usual web.config transformation methods? http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx

You can execute the code below, which will replace your entire section with the one below. Actually, what you have in your questions should replace your entire section with the one you provided, if this is your Web.Release.config file.

Web.Release.config:

 <plugins> <add name="bleh"> <option name="foo" value="bar"/> </add> </plugins> 
0
source share

Have you considered using configSource ? This allows you to split the configuration files into several smaller files. Web.config will go from:

 <configuration> <plugins> <add name="bleh"/> </plugins> </configuration> 

To do this using configSource:

 <configuration> <plugins configSource="plugins.config"/> </configuration> 

The downside is that you will not get a good user interface for editing configuration values ​​during deployment. This should be considered if you cannot get parameterization to work. If the installation user interface is what you need, you can code an editing tool for your administrators that can create and modify plugin.xml files.

0
source share

All Articles