Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
WiX Cookbook

You're reading from   WiX Cookbook Over 60 hands-on recipes packed with tips and tricks to boost your Windows installations

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher
ISBN-13 9781784393212
Length 260 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Nicholas Matthew Ramirez Nicholas Matthew Ramirez
Author Profile Icon Nicholas Matthew Ramirez
Nicholas Matthew Ramirez
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Organizing and Building WiX Projects FREE CHAPTER 2. Installing Files and Directories 3. File and Folder Permissions 4. Shortcuts 5. Editing XML Files during Installation 6. Custom Actions 7. Installing Wizards 8. Users and Groups 9. Handling Prerequisites 10. Installing Websites 11. Linking to the Web 12. Installing SQL Server Databases 13. Admin Tasks Index

Installing WiX and creating a new project in Visual Studio 2013

It's possible to work with WiX outside of Visual Studio, but within it, you'll benefit from the project templates; IntelliSense and shortcuts to the compiler and linker settings are available on the project's properties. The only downside is that WiX doesn't work with Visual Studio Express. However, its installer will give you the compiler and linker so that you can still get work done even if you're using Notepad to write the markup. SharpDevelop, a free and open source IDE, also supports WiX projects.

Getting WiX up and running starts with downloading and running its installer. This is a one-stop shop to update Visual Studio, getting the compiler and linker as well as other utilities to work with MSI packages. WiX supports Visual Studio 2005 and later, including Visual Studio 2013, which we'll cover here. In this recipe, we will download and install WiX and create our first setup project.

Getting ready

To prepare for this recipe, install Visual Studio 2013 and close it before installing WiX.

How to do it…

Download and install the WiX toolset to get access to new project templates, IntelliSense, and project properties in Visual Studio. The following steps will guide you:

  1. Open a browser, navigate to http://www.wixtoolset.org, and follow the link to the downloads page:
    How to do it…
  2. Once downloaded, launch the WiX installer and click on Install:
    How to do it…
  3. After completing the installation, open Visual Studio and go to File | New | Project | Windows Installer XML.
  4. Select the Setup Project template from the list of available project types. The version of .NET that's displayed has no bearing on the project since it's comprised of XML mark-up and not .NET code. Give the project a name and click on OK:
    How to do it…
  5. The project will initially include a file named Product.wxs, which contains the skeleton markup you'll need to create an installer:
    <?xml version="1.0" encoding="UTF-8"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
      <Product Id="*" 
          Name="My Software" 
          Language="1033" 
          Version="1.0.0.0" 
          Manufacturer="My Company" 
          UpgradeCode="889e2707-5235-4d97-b178-cf0cb55d8ab8">
        <Package InstallerVersion="200" 
          Compressed="yes" 
          InstallScope="perMachine" />
    
        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />
    
        <Feature Id="ProductFeature" 
          Title="MyFirstWixProject" Level="1">
          <ComponentGroupRef Id="ProductComponents" />
        </Feature>
      </Product>
    
      <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
          <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" 
              Name="My Software" />
          </Directory>
        </Directory>
      </Fragment>
    
      <Fragment>
        <ComponentGroup Id="ProductComponents" 
          Directory="INSTALLFOLDER">
          <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
          <!-- <Component Id="ProductComponent"> -->
            <!-- TODO: Insert files, registry keys, and other resources here. -->
          <!-- </Component> -->
        </ComponentGroup>
      </Fragment>
    </Wix>

How it works…

The WiX team has always worked quickly to keep up with the latest versions of Visual Studio. For example, WiX 3.9 supports Visual Studio 2013. When we launched the installer, it checked which versions of Visual Studio were present and registered its project templates with all that were compatible.

Behind the scenes, WiX introduces a new project type that has a .wixproj file extension. This project file contains MSBuild markup, which points to the WiX compiler and linker. Other IDEs, such as SharpDevelop, can take advantage of these project files to build MSI packages too.

The Product.wxs file contains everything we need to get started with writing WiX markup. The best coding practices for how to structure a WiX file have been defaulted for you. For example, the Directory elements are separated into a Fragment element so that directories are decoupled from the files that will go into them. A ComponentGroup has been set up with a comment guiding you to add Component elements to it. Each version of WiX brings a better Product.wxs file with it.

There's more…

If you were curious about what effect changing the version of the .NET framework listed in the drop-down list at the top of the New Project window would have, the answer, at least for setup projects, is nothing at all. A WiX file contains XML and is compiled with a specialized WiX compiler, so the version of .NET that we select will ultimately be ignored. That's not to say that it doesn't make a difference for any of the other project types. For example, C# Custom Action Project will have a dependency on the version of .NET that's selected. Anyone who uses the installer that in turn uses that custom action will need to have that version of .NET installed.

You have been reading a chapter from
WiX Cookbook
Published in: Jan 2015
Publisher:
ISBN-13: 9781784393212
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image