A launch condition is used to define the server requirements for your application installation.
For example, you can check for specific versions of Windows or verify that specific service packs are present before you allow an installation. The web setup template includes the IIS launch condition. This searches for the presence of the correct version of IIS and displays an error message to users if this version is not present, as shown in Figure 8-19.
fIGURE 8-19 The Launch Conditions error message.
To create and manage launch conditions, you use the Launch Conditions editor in Visual Studio. You can access this tool by selecting your project in Visual Studio and then clicking the View menu. You will see an Editor submenu that contains several setup editors, including those for Registry, File System, File Types, User Interface, Custom Actions, and Launch Conditions.
Selecting the Launch Conditions submenu opens the Launch Conditions editor, as shown in Figure 8-20. Notice that you right-click the Launch Conditions folder to add a new condition (this is discussed more fully in the next section).
fIGURE 8-20 Using the Launch Conditions editor to configure requirements for a target computer.
There are two main branches of the Launch Conditions editor: Search Target Machine and Launch Conditions. Each is described here:
■ Search Target Machine This branch allows you to define the criteria to search for prior to installation. By default, this node contains nodes for searching for major and minor ver-sions of IIS. You can add file, registry, and Windows Installer search conditions. Typically, you pair a search condition that determines whether a change is necessary with a launch condition that performs the change.
■ Launch Conditions This branch allows you to create new launch conditions that define conditions that must be met prior to installation. These conditions can be based on search conditions or other criteria (such as the operating system version). A launch condition can provide a useful message to the user if a requirement is missing.
It can then automatically retrieve a webpage. By default, Web Setup Projects include conditions for ensuring the presence of the correct version of IIS (later than version 7, for example).
Typically, you must add an item to each of these two nodes to require a single component as part of your installation. For example, if you want to verify that a specific DLL is present, you must create a search condition under Search Target Machine and store the result of the search in a property. You then create a launch condition that uses the search condition’s property.
If the required condition is not met (if the file is missing), you specify an error message to be displayed to the user. You can also choose to add a URL that directs the user to the required component for download.
ADDINg A SIMPLE SEARCH CoNDITIoN
You can add both search and launch conditions manually by right-clicking the appropriate folder and choosing an item to add. This allows you to create both search and launch conditions at a granular level and decide how to connect them.
To add a basic search condition, start by right-clicking the Search Target Machine node in the Launch Conditions editor. You will have three search condition types to choose from: Add File Search, Add Registry Search, and Add Windows Installer Search. Each is a different search type. Depending on your selection, different property values must be set. The following pro-vides an overview of each search type’s options.
■ file Search This search type allows you to define a search for a file. You set FileName to the name of the file you are searching for, Folder to the name of the folder in which to search, and Property to a variable name to be used for tracking the results of the search.
■ Registry Search This search type allows you to specify a registry search. You set the Root property to a place to start looking in the registry, RegKey to a registry key to search for, and the Value property to a value you expect to be set for the specified key.
You store the results of your search in the Property property as a variable name that can be used in a related launch condition.
Lesson 3: Deploying Websites CHAPTER 8 431
■ Windows Installer Search This search type allows you to search for a registered com-ponent. You set the ComponentId property to the globally unique identifier (GUID) of the component for which you are searching. You set the Property property to a vari-able that indicates the results of your search.
You can also rename your search and launch conditions to something that makes sense to your specific scenario.
ADDINg A SIMPLE LAUNCH CoNDITIoN
You can manually add a launch condition that must be met before your website can be installed.
To do so, you right-click the Launch Conditions folder, and then select Add Launch Condition.
With the new launch condition selected, you access the Properties window to configure your launch condition. You can set the Condition property to match the Property value of a search condition or to specify a different condition entirely. To allow the user to download software to resolve the launch condition, provide a URL in the InstallUrl property. In the Message property, type a message to be displayed to the person installing your website if a condition is not met.
You can configure launch conditions to require specific operating system versions, specific ser-vice pack levels, and other criteria by setting the Condition property to an environment variable or keyword and using both an operand and a value. Table 8-5 lists some common launch conditions.
TABLE 8-5 Windows Installer Launch Conditions
CoNDITIoN DESCRIPTIoN
VersionNT The version number for operating systems based on Windows NT, including Windows 2000, Windows XP, and Windows Server 2003 Version9X The version number for early Windows consumer operating
systems, including Windows 95, Windows 98, and Windows Millennium Edition
ServicePackLevel The version number of the operating system service pack WindowsBuild The build number of the operating system
SystemLanguageID The default language identifier for the system
AdminUser The tool that determines whether the user has administrative privileges PhysicalMemory The size of the installed RAM in megabytes
IISMAJORVERSION The major version of IIS, if installed IISMINORVERSION The minor version of IIS, if installed
To evaluate environment variables, preface the variable name with a % symbol, as this example illustrates.
%HOMEDRIVE = "C:" (verify that the home drive is C)
To simply check a property for a specific value, you can use the = operator, as the following example shows.
IISVERSION = "#6" (check for IIS 6.0) VersionNT = 500 (check for Windows 2000)
You can also check for ranges.
IISVERSION >= "#7" (check for IIS 4.0 or later) Version9X <= 490 (check for Windows Me or earlier)
You can also check for multiple conditions by using Boolean operators: Not, And (which returns true if both values are true), Or (which returns true if either value is true), Xor (which returns true if exactly one value is true), Eqv (which returns true if both values are the same), and Imp (which returns true if the left term is false or the right term is true). The following example demonstrates a Boolean operator.
WindowsBuild=2600 AND ServicePackLevel=1 (check for Windows XP with Service Pack 1) CREATINg PREgRoUPED LAUNCH CoNDITIoNS
You can also create pregrouped search and launch condition sets for common scenarios. Do-ing so simply creates both a search and a launch condition, with both items preconfigured to work together. You simply need to adjust their properties according to your needs. To create a grouped launch condition, you right-click the root node in the Launch Conditions editor (Requirements On Target Machine) and select one of the following:
■ Add File Launch Condition
■ Add Registry Launch Condition
■ Add Windows Installer Launch Condition
■ Add .NET Framework Launch Condition
■ Add Internet Information Services Launch Condition
As an example, adding file-based conditions (such as DLL conditions) is a common practice.
The following steps walk through the creation of a file-based, pregrouped launch condition:
1. In the Launch Conditions editor, right-click the Requirements On Target Machine root node. Select Add File Launch Condition to get started.
The Launch Conditions editor adds a search condition (Search For File1) to the Search Target Machine node and a launch condition (Condition1) to the Launch Conditions node. The new search condition’s Property property value has a default name of FILEEXISTS1. This value links it to the Condition property of the launch condition.
2. You can rename both the new search condition and the new launch condition so that the names indicate the file you are searching for.
Figure 8-21 shows an example of both conditions added to the Launch Conditions editor.
Notice that the Search For File1 condition is selected and its Properties window is dis-played. Notice that the Property property is set to FILEEXISTS1.
Lesson 3: Deploying Websites CHAPTER 8 433 fIGURE 8-21 The file search criterion and related condition.
3. In Figure 8-21, notice that there are several search condition properties in the Properties window. For a file search, you typically configure these properties as described in Table 8-6.
TABLE 8-6 File Search Condition Properties
PRoPERTY DESCRIPTIoN
FileName The name of the file to look for. Just specify the file name with its extension, not the folder.
Folder The folder in which to search for the file. Here you can select a special folder such as [CommonFilesFolder] or [WindowsFolder].
You can also hardcode a direct path to the file. You can search subfolders by specifying the Depth field.
Depth The number of nested folders within the specified folder to search.
MinDate,
MaxDate The minimum and maximum last modified date of the file.
MinSize, MaxSize The minimum and maximum size of the file.
MinVersion,
MaxVersion The minimum and maximum version of the file.
Property The name of the property that stores the results of this search.
You specify this property name in the corresponding launch condition.
4. Next, you select the new launch condition and view its Properties window. The properties are typically configured as described in Table 8-7.
TABLE 8-7 Launch Condition Properties PRoPERTY DESCRIPTIoN
Condition The condition that must evaluate to true for installation to continue. By default, this is the name of a property assigned to a search condition, and if the search finds the required file or other object, the launch con-dition is fulfilled. You can specify more complex concon-ditions to check for operating system version, service pack levels, and other criteria.
InstallUrl The URL to be retrieved by the setup project if the launch condition is not met. The user can access this resource to install the required component. This is an optional setting.
Message The message that is displayed to the user if the launch condition is not met.
In this example, the setup project would look for the dependent file as configured in the search condition. The launch condition would then execute and throw an error if the file is not found.