Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
WiX Cookbook

You're reading from  WiX Cookbook

Product type Book
Published in Jan 2015
Publisher
ISBN-13 9781784393212
Pages 260 pages
Edition 1st Edition
Languages
Author (1):
Nicholas Matthew Ramirez Nicholas Matthew Ramirez
Profile icon Nicholas Matthew Ramirez

Table of Contents (20) Chapters

WiX Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Organizing and Building WiX Projects 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

Chapter 9. Handling Prerequisites

In this chapter, we will cover the following recipes:

  • Stopping the installation with a launch condition

  • Installing only to supported versions of Windows

  • Redistributing the .NET Framework with a bootstrapper

  • Executing either a 64-bit or 32-bit MSI depending on the user's operating system

  • Downloading resources from the Web with a web installer

Introduction


We have several options when it comes to handling prerequisites needed by our installer. When I say prerequisites, I mean frameworks such as .NET, databases such as SQL Server, and the environment itself such as having the expected version of Windows. We can stop the installation outright if our requirements aren't met. On the other hand, in some cases, we may choose to download the missing items. For example, if the end user is missing the .NET Framework, we can install it prior to installing our own software.

In this chapter, we'll cover several scenarios, including how to prevent installations to the wrong environment, download components from the Web, and install either 32-bit or 64-bit files depending on which architecture the operating system supports.

Stopping the installation with a launch condition


A launch condition checks the user's computer to make sure that it can support our software. If it can't, the installation is automatically stopped before the user can go any further. For example, we may want to prevent the installation if the user doesn't have the necessary version of .NET installed. In this recipe, we'll do just that by adding a condition that checks for .NET Framework 4.5.

Windows 8 comes with .NET 4.5 preinstalled, but Windows 7 doesn't. We can use NetFxExtension to check whether .NET 4.5 is preinstalled, and if it's missing, a message is displayed telling the user that the installation cannot continue. A nice thing about launch conditions is the ability to show the user a warning message explaining what went wrong.

Getting ready

To get started, perform the following steps:

  1. Create a new setup project and name it LaunchConditionInstaller.

  2. Add a reference to NetFxExtension by right-clicking on the References node in Solution...

Installing only to supported versions of Windows


Once we're confident that our application works on a particular version of Windows, we may want to prevent users from installing to other unsupported operating systems. Here, we can use a launch condition. Launch conditions evaluate the state of the user's system and then cancel the installation if our requirements aren't met. By checking the operating system version, we can save the end user from trying to use our software on a system it was never intended for.

Getting ready

Create a new setup project and name it SupportedWindowsInstaller.

How to do it...

Add a launch condition that checks the VersionNT property to see what the computer's version of Windows is:

  1. Add a Condition element inside the Product element. Its Message attribute will explain that the current operating system is not supported, as follows:

    <Condition Message="Only Windows 8 and up is supported">
    </Condition>
  2. Add a conditional statement inside that element that compares...

Redistributing the .NET Framework with a bootstrapper


A bootstrapper checks for prerequisites and installs them if they're missing. So, we could install .NET or SQL Server if it's not present and then follow up by installing our own software. WiX Toolset adds a Visual Studio project template called Bootstrapper Project. In this recipe, we'll see how to deploy the .NET Framework with it.

Getting ready

Create a new setup project and call it InstallerThatNeedsDotNet. We'll use a bootstrapper to bundle this MSI with the .NET Framework.

How to do it...

Add a bootstrapper project, reference NetFxExtension within it, and then include one of its .NET packages in the bootstrapper:

  1. Add a Bootstrapper Project to the solution by right-clicking on the solution in Solution Explorer and going to Add | New Project... | Windows Installer XML | Bootstrapper Project | OK:

  2. NetFxExtension contains packages to install .NET. Add it to the project by right-clicking on the References node in Solution Explorer and going...

Executing either a 64-bit or 32-bit MSI depending on the user's operating system


An MSI can target a 64-bit or 32-bit processor architecture, but never both. An MSI contains metadata called Template Summary that denotes which architecture it supports, and it can only support one or the other at a time. However, there is a way to give the user a single package that will install either 64-bit or 32-bit software, depending on their operating system. In this recipe, we will build such a package, combining both architectures into a single bootstrapper bundle.

Getting ready

To prepare for this recipe, follow these steps:

  1. Create two new setup projects within the same Visual Studio solution. The first is our 32-bit installer and is called ThirtyTwoBitInstaller. It targets ProgramFilesFolder in its directory structure:

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" 
                   Name="ThirtyTwoBitInstaller" />
     ...

Downloading resources from the Web with a web installer


A web installer is a bootstrapper that downloads some or all of its resources from the web during installation. This way, the initial download of the bootstrapper is faster, since its file size is much smaller. The main portion of it is hosted online where it's only downloaded when you need it. The disadvantage is that end users will need an Internet connection when they run the installer. However, in many cases, that's a small price to pay.

In this recipe, we'll need to have our resources hosted online. When I say resources, I'm talking about MSI packages, other executable installers, and patch files. To give you an idea about how it would work, we'll use an MSI file that's already on the Web: the Node.js installer.

Getting ready

To prepare for this recipe, perform the following steps:

  1. Create a new bootstrapper project and call it WebInstaller.

  2. Download the Node.js MSI from http://nodejs.org/download and copy it to the directory of the...

lock icon The rest of the chapter is locked
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 $15.99/month. Cancel anytime}