Is it possible to insert an XML element into my web.config using Web Deploy's Parameters.xml system?
The XmlFile parameter "kind" appears to be the closest to what I need, but its match
attribute only accepts an XPath query, and I don't appear to be able to specify a non-existent element in my XPath query. (Or rather, I can specify a non-existent element - Web Deploy just ignores it.) Specifically, I would like to transform this:
<configuration>
<plugins>
<add name="bleh"/>
</plugins>
</configuration>
into this:
<configuration>
<plugins>
<add name="bleh">
<option name="foo" value="bar"/>
</add>
</plugins>
</configuration>
(Unfortunately I can't pre-stock the web.config with an empty option
element because this particular plugin system doesn't like unrecognized/empty options.)
Thanks for any ideas!
Such things are now possible starting with the Web Deploy V3. See the official documentation.
Here is one example of a parameters.xml file which will add newNode to all nodes including the root in target xml file:
<parameters>
<parameter name="Additive" description="Add a node" defaultValue="<newNode />" tags="">
<parameterEntry kind="XmlFile" scope=".*" match="//*" />
</parameter>
</parameters>
Xpath is only a query language for XML documents -- it cannot by itself change an XML document or create a new XML document.
The language especially designed for transforming 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 transformation is applied on the provided XML document:
<configuration>
<plugins>
<add name="bleh"/>
</plugins>
</configuration>
the wanted, correct result is produced:
<configuration>
<plugins>
<add name="bleh">
<option name="foo" value="bar"/>
</add>
</plugins>
</configuration>
Have you considered using configSource? This allows you to split up your configuration files into multiple smaller files. The web.config would go from:
<configuration>
<plugins>
<add name="bleh"/>
</plugins>
</configuration>
To this with configSource:
<configuration>
<plugins configSource="plugins.config"/>
</configuration>
The downside is You won't get a nice UI for editing config values during deployment. It is something to consider if you cannot get parameterization to work. If the install UI is what you are after then you could code an editing tool for your admins that can create and modify the plugin.xml files..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With