Creating a Web Application Installer with WiX 3.5 and Visual Studio 2010–Part 2

Continuing on from Part 1, we take a look at applying some general settings, and checking of prerequisites.

Step 3: General Settings

There are various general settings (or properties) that you are likely to want to apply to your WiX project such as defining the main icon to use in the programs list.  A full list can be found at the Windows Installer Property Reference.

With the assumption that this may well grow over time, it’s probably a good idea to define these in a separate file to minimise the clutter in the main Product file.

This can be achieved by adding a WiX Include File to the installer project:

Product.wxs
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="d5b59d53-5fbb-4dd4-a2ac-1e97d70710b3"
           UpgradeCode="c72f2c40-88b1-4a8f-8800-1796cf0dbafe"
           Version="1.0.0.0"
           Name="!(loc.ProductName)"
           Language="!(loc.LANG)"
           Manufacturer="!(loc.CompanyName)">
        <Package InstallerVersion="200" Compressed="yes"
             Languages="!(loc.LANG)"
             Manufacturer="!(loc.CompanyName)" Comments="!(loc.Comments)"
             Description="!(loc.Description)" Keywords="!(loc.Keywords)"/>

    <?include Settings.wxi ?> <!-- Apply our settings -->

And then populating your Settings file with any appropriate properties, e.g.

Settings.wxi
<?xml version="1.0" encoding="utf-8"?>
<Include>
  <Icon Id="icon.ico" SourceFile="pslogo.ico"/>
  <Property Id="ARPPRODUCTICON" Value="icon.ico" />

  <MajorUpgrade Schedule="afterInstallInitialize"
                DowngradeErrorMessage="!(loc.DowngradeErrorMessage)"/>
</Include>

(Don’t forget to include your actual icon file in the project too!)

Step 4: Conditions

It also pretty certain there are going to be a number of condition checks that need to be performed before you can proceed with any installation, so again, it’s probably neater to factor these checks into a separate include file too:

Product.wxs
<?include Settings.wxi ?>   <!-- Apply our settings -->
<?include Conditions.wxi ?> <!-- Perform conditional checks -->

And some conditions:

Conditions.wxi
<?xml version="1.0" encoding="utf-8"?>
<Include>

  <!-- Check that we have elevated permissions if installing -->
  <Property Id="MSIUSEREALADMINDETECTION" Value="1" />
  <Condition Message="!(loc.Administrator)">Installed OR (Privileged AND AdminUser)</Condition>

  <!-- IIS Version 6 or higher check. -->
  <PropertyRef Id="IISMAJORVERSION"/>
  <Condition Message="!(loc.IISVersion)">IISMAJORVERSION &gt;= "#6"</Condition>

  <!-- .NET 4 Version Check -->
  <PropertyRef Id="NETFRAMEWORK40FULL"/>
  <Condition Message="!(loc.DotNet4)">Installed OR NETFRAMEWORK40FULL</Condition>

  <!-- RIA Services Check: Cannot just check key - need value, hence v1.0->InstallPath -->
  <Property Id="RIASERVICES">
    <RegistrySearch Id="RiaServices" Name="InstallPath" Root="HKLM"
                    Key="SOFTWARE\Microsoft\WCFRIAServices\v1.0" Type="raw" />
  </Property>

  <Condition Message="!(loc.RiaServices)">Installed OR RIASERVICES</Condition>

</Include>

In the above conditions we:-

  1. Turn on the MSIUSEREALADMINDETECTION which requests that the installer use the actual user information when setting the AdminUser property.  And then check whether we are already installed, or we are suitably privileged administrators.  I’m still not convinced that this condition is 100% ideal, but it was the only one I found that checked and warned on various operating systems I tried it on (Windows 7, Windows 2008 and Windows 2003).  Please comment if you have a neater condition check than this! Smile
  2. We only want to support IIS 6 upwards.  WiX 3.5 comes with various extension assemblies that you can add to your installer project, one of which is WixIIsExtension.  Add a reference to this assembly, and then you can make use of the PropertyRef statement shown above along with a whole load of other functionality we will look at later.
  3. We want to ensure we have the full version of .NET 4 installed. Again, WiX 3.5 comes with an extension to support .NET, namely WixNetFxExtension…so add this one too so our PropertyRef works.
  4. Check that RIA Services is installed (somewhat more context specific but gives you an idea for performing other similar checks!).  In this case, we look up a value at a particular registry key to determine if the product is installed.

Some general tips with the extensions: at this point in time, there’s not a great deal of documentation on everything that they can do and provide…and as we all know, that’s only natural as documentation invariably trails behind the pace we set putting out new software.  As a result, I found it helpful to look into the source code for these both WiX and the extensions to find out more about what they offered.

You may also find older examples that perform a check to ensure that IIS compatibility is installed.  WiX 3.5 contains native support for IIS 7, so we no longer need to perform this check.  We just have to be careful later on when creating our custom actions that we do not introduce any dependency on IIS compatibility if IIS 7 is being used.

In the next post( s), we’ll look at providing an interface, defining a structure and dealing with IIS.

Print | posted on Thursday, 24 February 2011 5:47 PM

Feedback

# online sales

left by MyWebsiteNow at 24/06/2011 8:59 PM Gravatar
Enormous piece of writing! I really appreciate this wonderful post that you have provided for us. I utterly agree with you. I regularly read your blog and its very helpful.
online sales
Title  
Name
Email (never displayed)
Url
Comments   
Please add 8 and 4 and type the answer here: