Automatic account creation is now enabled. Captcha authentication required for account creation and editing unless you are trusted here.

WiX XmlConfig

From WiX Wiki at MindCapers

Jump to: navigation, search

Sample

I got this working in the end - the XMLConfig does support the manipulation of XML attributes.

In case anyone Googles this, something like this will work:

 
 <util:XmlConfig Id='InsertSchemaLocationAttribute'
            Action='create'
            ElementPath='/xs:schema/xs:include[\[]not(@schemaLocation)[\]]'
            File='[FILENAME]Microsoft.Build.xsd'
            Name='schemaLocation'
            Node='value'
            On='install'
            Sequence='2'
            Value='MSBuild\File.xsd' />
 

The above adds a "schemaLocation" attribute with the value to the element found at the ElementPath (actually the first "include" element with no "schemaLocation" location).

Q&A

Question

I've been trying to use the XmlConfig node in WiX v3.0. What I'm trying to do is to append a new "add"-node under /configuration/system.data/DbProviderFactories (in machine.config) that should be removed on uninstall. I think I've figured out how to add it properly, but I still don't understand how to remove it!

The installation script looks something like this:

 
 <util:XmlConfig 
        Id="Machine_Config_Xml_Root"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        Action="create" 
        On="install"
        ElementPath="//configuration/system.data/DbProviderFactories" 
        Name="add"
        Node="element" 
        Sequence="1"> 
 </util:XmlConfig> 
 <util:XmlConfig 
        Id="Machine_Config_Xml_2"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        ElementPath="Machine_Config_Xml_Root"
        Name="invariant"
        Value="MTNE.Framework.Data.CslClient" 
        Sequence="2"> 
 </util:XmlConfig>
 

Which creates a node looking like this:

 
 <add invariant="MTNE.Framework.Data.CslClient"/>
 

But how do I remove it? I've tried this:

 
 <util:XmlConfig 
        Id="Machine_Config_Xml_Uninstall_1"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        Action="delete"
        On="uninstall"
        ElementPath="//configuration/system.data/DbProviderFactories/add[\[]@invariant='MTNE.Framework.Data.CslClient'[\]]"
        Sequence="1">
 </util:XmlConfig>
 

but that doesn't seem to do anything at all...

Finally, an other (related?) question.. What is the VerifyPath attribute used for?

Answer

I'm not an expert with XmlConfig yet but my understanding is that VerifyPath is used to tell if the element/attribute is actually present. With VerifyPath specified the CustomAction can tell during repair and during uninstall if the element/attribute needs to be fixed/removed. VerifyPath is what was missing from the old XmlFile implementation that couldn't handle all repair and uninstall scenarios well.

I think you'll get the uninstall to work if you provide the VerifyPath.

Question
I am trying to get the XmlConfig Element to work but I get an "element contains unexpected child element" error when I use the "XmlConfig" element.
Answer
If you're using WiX v3, you need to add the WixUtilExtension to your command lines and use <util:XmlConfig> to refer to the WixUtilExtension namespace.
Personal tools