Deleting XML elements in WiX
Asked Answered
E

2

18

How do you delete/remove an element from an XML file in WiX?

Egret answered 15/1, 2010 at 0:59 Comment(0)
E
21

Given a .config file with the following content:

<configuration>
 <thingy>
  <stuff>
   <item type='value' />
   <item type='value2' />
  </stuff>
 </thingy>
</configuration>

To remove the item element with the type attribute set to 'value' this seems to do the trick:

<util:XmlConfig
  On="install"
  Action="delete"
  Id="RemoveAnElement"
  Node="element"
  File="Application.dll.config"
  VerifyPath="/configuration/thingy/stuff/item[\[]@type='value'[\]]"
  ElementPath="/configuration/thingy/stuff"
  Sequence="100"
/>

This XmlConfig element is defined by the Wix "Utility" extension. To use that extension, you have to declare the UtilExtension namespace like this:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
   xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">

You also have to add -ext WixUtilExtension to the light.exe command options, or add a reference to "WixUtilExtension.dll" if you are authoring a wix project using votive in visual studio.

Egret answered 15/1, 2010 at 1:22 Comment(2)
ElementPath points to the parent of VerifyPath. Very helpful, Thanks!Padlock
Using WiX 3.6, I also had to add -ext WixUtilExtension to candle.Munsey
L
4

I know this is old, but I searched everywhere for my issue and never could find it until I finally stumbled upon the answer. So maybe by posting here someone will find it useful.

In addition to the above answer, if using V4.0 the xmlns:util link should look like this:

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" 
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util" >

Otherwise you will get the error:

The Component element contains an unhandled extension element 'util:Blah'. Please ensure that the extension for elements in the 'http:⁄⁄schemas.microsoft.com⁄wix⁄UtilExtension' namespace has been provided.

Lovely answered 1/5, 2013 at 2:34 Comment(1)
Thanks for addition the info for v4Egret

© 2022 - 2024 — McMap. All rights reserved.