Book Image

WiX Cookbook

By : Nicholas Matthew Ramirez
1 (1)
Book Image

WiX Cookbook

1 (1)
By: Nicholas Matthew Ramirez

Overview of this book

Table of Contents (20 chapters)
WiX Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding an XML element only if it does not already exist


In this recipe, we'll learn a technique of adding an XML element only if it isn't already present. When updating a configuration file that's shared amongst applications, such as the machine-level Web.config file, you might use this to keep old user settings intact or else create them anew if they aren't already set. For this recipe, we'll check for the existence of an element called add with a key attribute of UserSetting1 and add it if it isn't already there.

Getting ready

To prepare for this recipe, perform the following steps:

  1. Create a new setup project and call it XmlElementExistsInstaller.

  2. Add an XML file called Web.config with the following markup:

    <?xml version="1.0"?>
    <configuration>
      <appSettings>
        <add key="UserSetting1" value="abc" />
      </appSettings>
    </configuration>
  3. Add a Component element to Product.wxs to include the file in the installation:

    <ComponentGroup Id="ProductComponents" ...