WIX v3 and XmlConfig / XmlFile troubleshooting

Published 09 October 07 09:18 PM | gisenberg 

I've recently been tasked with implementing deployment automation for each component of a relatively large project. Armed with a colleague who had done similar work before, I dove into WiX with a great resource at hand :)

Let me preface this whole thing by saying that, despite the snags I've ran into, WiX is absolutely worth the effort. For as easy as WiX is to implement, it's criminal to *not* implement it in your project. Currently, the entire deployment process we have takes around 10-15% of the team's time. Dev and Test come up with a release plan, review with the program manager and release manager, refine, revise, rinse and repeat. Then, when the time to deploy actually comes, a hole in the document everyone signed off on becomes apparent. WiX helps solve that dilemma.

My goal was to add an entry to the machine.config file's appSettings node. I needed to output: <add key="MSCOM/Environment" value="[MyVariable]" />

I wasn't able to find a lot of great documentation on this, so I'm hoping to save someone else some time :) That said, let's move ahead to the XmlConfig/XmlFile issues I ran into:

  1. XmlConfig, despite my best efforts, didn't seem to actually *do* anything. Taking known-good examples yielded absolutely no edits to my target file. The root cause? At the time of this post, the latest build of WiX available on the Sourceforge download page 3.0.2925; however, the actual latest build is 3.0.3405 (http://wix.sourceforge.net/releases/). In build 2925, XmlConfig seems totally broken, but in build 3405, it functions as expected.
  2. Before realizing that a newer build was available, I resigned and tried to utilize an XmlFile to perform the same task. This proved difficult for a variety of reasons; XmlConfig lets you pass an ID to a new element, where XmlFile makes you do an XPath query each time. This results in a hacky solution where you create a temporary value, do queries based on that temporary value, and then null the value of the newly created node when done. Once this has been done, uninstalling doesn't remove the nodes. For manipulating Xml documents, XmlConfig is the way to go.
  3. Once I updated builds and XmlConfig was "working", the XmlConfig node wasn't actually creating a new element. The second XmlConfig node that added an attribute couldn't find the XmlElement created previously. I had to scope down from all attributes to a specific set of attributes to get something to create.
  4. Once I had my <add> node being written to the file, my attributes wouldn't get written. To successfully write attributes to a newly created node, I had to scope down my XmlConfig node to a few select attributes. Specifically, I believe having "Action" and "Node" values trips up the Util assembly.
  5. Once I had my attributes writing to the correct node, my uninstall process wouldn't remove the node it added. I added an XmlConfig node with On="uninstall" that *seemed* right. However, the parameters you expect to pass to XmlConfig vary by operation; it takes using the same attributes differently to actually do something on an uninstall. Specifically, ElementPath points to the *parent* node of the node you want to delete, and the VerifyPath is an XPath query to the node you want to delete, relative to the ElementPath.
  6. Documentation on XmlConfig is not good enough; the way you utilize parameters vary based on operation. The documentation doesn't make this apparent, leaving you to trial and error and a dozen searches that don't yield a solution.

The actual XML snippet I ended up using to get a successful uninstall/reinstall process was:

                <util:XmlConfig
                    Id="MachineConfigAdd"
                    File="[DOTNETCONFIGPATH]\machine.config"
                    Action="create"
                    ElementPath="//configuration/appSettings"
                    Name="add"
                    Node="element"
                    Sequence="1"
                    On="install" />
               
                <util:XmlConfig
                    Id="MachineConfigKey"
                    File="[DOTNETCONFIGPATH]\machine.config"
                    ElementPath="MachineConfigAdd"
                    Name="key"
                    Value="MSCOM/ConfigEnvironment"
                    Sequence="2" />
               
                <util:XmlConfig
                    Id="MachineConfigValue"
                    File="[DOTNETCONFIGPATH]\machine.config"
                    ElementPath="MachineConfigAdd"
                    Name="value"
                    Value="[ENVIRONMENT]"
                    Sequence="3" />
               
                <util:XmlConfig
                    Id="MachineConfigRemoveNode"
                    File="[DOTNETCONFIGPATH]\machine.config"
                    Action="delete"
                    Node="element"
                    VerifyPath="add[\[]@key='MSCOM/ConfigEnvironment'[\]]"
                    ElementPath="//configuration/appSettings"
                    On="uninstall"
                    Sequence="1" />

I can only hope that this saves someone, somewhere a headache :)

 

Filed under: , , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Techy News Blog » WIX v3 and XmlConfig / XmlFile troubleshooting said on October 9, 2007 5:01 PM:

PingBack from http://www.artofbam.com/wordpress/?p=6558

# si said on November 21, 2007 11:59 PM:

As that someone (and I'm sure there are other someones too:)...THANK YOU!

May the RROD never touch your 360 :)

# tomc said on January 10, 2008 5:27 PM:

Thanks you save me a couple of headaches as well!  Much appreciated.

# Zhisheng Huang's Blog said on July 23, 2008 8:48 PM:

Can't find good documents on WIX XmlConfig. There are some posts with examples that help me getting started:

# KevinI said on August 22, 2008 6:35 PM:

Any idea how to use XmlConfig if there is a Namespace in the XML file?

# Sourabh Jain said on October 12, 2008 4:50 AM:

Well this is simply great I guess WIX has many undocumented features. This one is really one of them. Thanks...

# Murray said on October 20, 2008 1:19 AM:

Thanks for saving me from my already existing headache :)

# siaj said on November 7, 2008 5:05 PM:

Thanks a lot  ! It was really helpful after I spent 2 hours pulling my hair to find a solution using XmlFile.

# David said on November 20, 2008 4:40 PM:

Dude wow thank u, as previous statements i was trying to use XmlFile POS

# Insomnia said on December 12, 2008 8:47 PM:

thank you! thank you! thank you! thank you! thank you!

# Silly said on June 17, 2009 11:16 PM:

You are a rock star.  VerifyPath on delete... to specify the node to delete?  Without you, my life was over.

# Ugh said on July 6, 2009 1:00 PM:

Thanks!! I wasted a good couple hours on XmlFile before I found your post. You're a life saver.

# Andyb6905 said on July 24, 2009 7:16 AM:

Cheers this was a god send, saved me hours

# Patrick said on September 16, 2009 8:53 AM:

Thanks, this was a great help!

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

Search

This Blog

Syndication

Page view tracker