20.7 Conditionally Installing Files

 <  Day Day Up  >  

You want certain files to only be installed if certain conditions are satisfied.


Technique

Navigate to the files in question in the File System Explorer. Select each file and look at the VS.NET Properties Window. You see a field called Condition. Simply enter the condition in this field using the same format as for a launch condition. For example, to specify that the primary output from a certain project should only be installed on Windows 9x machines, specify the condition Version9x >= 400 .

A common use for this technique is to install a different set of files according to the operating system on the target machine. For example, you might have one assembly with the condition Version9x>=400 and an alternate assembly with the condition VersionNT>=400 . The first assembly is installed on Windows 95/98/XP machines, the second assembly on Windows NT/2000/XP/2003 Server family machines.

Notice that although we worked through the process for files, the procedure for conditionally installing is the same for other items, such as Registry keys. Simply navigate to the item in the appropriate editor and modify its Condition property in the VS.NET Properties Window. (You specify Registry keys to be installed with another of the setup project editors, the Registry Editor, but using a similar procedure to that for adding files.)

Although the syntax of the condition is the same for launch conditions and conditionally installing files, there is an additional flexibility when conditionally installing files: You can impose a condition based on choices selected by the user in a dialog box. This extra flexibility is not available for launch conditions for the simple reason that the launch conditions are evaluated before the setup program solicits any input from the user .

To show how to conditionally install a file based on a user option, we work through the process of putting up a dialog asking the user whether she wants to install diagnostic tools and conditionally install the primary output from a project called Tools only if the user indicates it is required.

First, we add a dialog to the install process as described in recipe 20.5, "Adding User-Interface Dialogs." We use a dialog that displays one check box, so we need to use one of the three check box dialogs.

We want the extra dialog to look like Figure 20.14.

Figure 20.14. Install Diagnostic Tools dialog.

graphics/20fig14.jpg

To achieve this we set the properties of the Checkboxes (A) dialog as shown in Figure 20.15.

Figure 20.15. Choosing properties to generate the Add Diagnostic Tools dialog.

graphics/20fig15.jpg

Figure 20.15 shows we typed in appropriate text for the banner text and body text. We also indicated that the first check box ( CheckBox1 ) is visible, but all other check boxes are not visible. The key point is the value of the CheckBox1Property property, which we set to INSTALLTOOLS . The effect is that after the user exits this dialog, a property of this name is made available to Windows Installer. This property has the value 1 if the user checked the check box and if the user didn't. To conditionally install a file based on this user selection, all that remains is to locate the file in question ”with our example, the primary output of the Tools project ”in the File System Editor and change its Condition to INSTALLTOOLS=1 .

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net