Monday, November 12, 2007

Changing the install directory dynamically (based on user input)

If you need to change/set a directory or a subdirectory dynamically "on the fly", either based upon a value from a dialog or some other means there are two things you need to do and one caveat:

1. Create a custom action that sets the directory value:

<customaction id="AssignWebDir" directory="WEBSITEDIRECTORY" value="[WEBSROOTDIR][DIRNAME]">

2. Schedule the action during the InstallExecution phase (must be after the CostFinalize step):

<custom action="AssignWebDir" after="CostFinalize"><![CDATA[NOT Installed AND (&WebServer = 3) AND NOT (!WebServer = 3)]]> </custom>

The reason why it work's is that, at the time you've scheduled the custom action the directory name, which is also a property, has been resolved. In the above example, assume that the parent directory, named WEBSROOTDIR, is the default "C:\Inetpub\wwwroot\". Under the parent directory is where you've specified WEBSITEDIRECTORY to be. Even though you may specify an initial directory name (e.g. "fiddler") on the tag in the .wxs file you must use the full path when changing the name - thus the new value in #1 above contains the parent directory name and the site name (Which is entered by the user in the UI).

The full condition is if the product is not installed (i.e. it's being installed) and if the Feature (in this case the "WebServer" feature) is being installed locally and it's not already installed locally. Finally the Directory= attribute causes WiX to create a Type 35 Custom Action whereas using Property= causes WiX to create a Type 51 Custom Action.

Tip:- <![CDATA[...]]> around the conditions "preserves" the xml integrity because of the ampersand (&) character in front of the Feature name.

Resolving the Unresolved reference to symbol 'CustomAction:ConfigureIIs'

This error occurs when you are building your MSI using light.exe and are getting the following
error LGHT0112 : Unresolved reference to symbol 'CustomAction:ConfigureIIs' in section....

When you look for the symbol in your .wxs, you dont find it there. Imagine it like not having a reference to a Dll which your .net code requires and you need to link a library. If your .wxs is modifying any websites or virtual directories, you need to link the appropriate wix library (its of type .wixlib). For Website and virtual directories, the library you need to include is sca.wixlib.

So your build command should be:
light.exe sca.wixlib SomeWxs.wixobj -out SomeMSI.msi

Tip:- Its important to give -out when you are giving more than 1 file as input to light.exe.
Other common libraries are: wixca.wixlib, wixui.wixlib.

Saturday, October 6, 2007

Introduction

The Windows Installer XML (WIX) is a toolset that builds Windows installation packages from XML source code. WIX toolset supports a command line environment that developers may integrate into their build processes to build MSI (Microsoft Installer Package) and MSM setup packages.

WIX is an open source project started by Microsoft. WIX is an entire toolset that takes XML files as input and compiles and links them into actual MSI databases.

This blog aims at answering your frequently asked questions on WIX installer, to help you create professional MSI setup packages.