it:ad:wix:howto:create_pre-launch_conditions

IT:AD:WiX:HowTo:Create pre-launch Conditions

It's rather useful to check the target environment before even bothering with an install. The two most common prechecks are

Does the target have the right OS? Does the target have the right .NET Framework? One way to do that is with the use of Condition element.

Placement

Conditions change behavior depending on where they are placed:

<Component|Control|Feature|Product>

  • Component

    > `Condition`: becomes a Condition of the Component.

    *

    Control

    > `Condition`: becomes ControlCondition entry.

*

Feature

> `COndition`: becomes a Condition entry.

*

Product

> `Condition`: becomes a LaunchCondition entry.

For example, a couple of Conditions placed under the Product element:

<Product …

>

      ...
      <!-- Launch conditions -->
      <Condition Message="This application is only supported on Windows Vista, 
                          Server 2008, or higher (32 or 64 bit).">
          <![CDATA[Installed OR (VersionNT >= 600) OR (VersionNT64 >=600)]]>
      </Condition>
      <Condition Message="This application is only supported on Windows Vista, 
                          Server 2008 (32 or 64 bit).">
          <![CDATA[Installed OR (VersionNT < 700) OR (VersionNT64 < 700)]]>
      </Condition>
  </Product>

#### Platform Check is WS2008+ or Vista, 32 or 64bit ####

<Component|Control|Feature|Product> <Condition Message=“This application is only supported on Windows Vista, Server 2008, or higher (32 or 64 bit).”

>

          <![CDATA[Installed OR (VersionNT >= 600) OR (VersionNT64 >=600)]]>
      </Condition>
  </Component|Control|Feature|Product>

#### Check for the .NET Framework ####
To check for the .NET Framework is nearly the same thing – except that you need variables that are only defined once you've included the NetFxExtensions.

So

Code:

<PropertyRef Id="NETFRAMEWORK20"/>

* Add the Condition that checks one or more of the vars defined in NetFxExtension

Code:

<Condition Message="This application requires .NET Framework 3.0 SP1. 
                Please install then try again.">
    <![CDATA[Installed OR (NETFRAMEWORK30_SP_LEVEL and NOT NETFRAMEWORK30_SP_LEVEL = "#0")]]>
</Condition>

Vars you could check on are:

NETFRAMEWORK20 (will be '#1' if Installed)
NETFRAMEWORK20_SP_LEVEL (will be '#0', or '#1', or...)
NETFRAMEWORK30
NETFRAMEWORK30_SP_LEVEL
NETFRAMEWORK35
NETFRAMEWORK35_SP_LEVEL
NETFRAMEWORK40FULL
NETFRAMEWORK40FULL_SERVICING_LEVEL
NETFRAMEWORK40CLIENT
NETFRAMEWORK40CLIENT_SERVICING_LEVEL