Using WiX on the command line

Windows Installer XML

Using a Custom Action

WiX provides a set of built-in custom actions that can be used in your installer package. In this example, we will create an installer that creates a shortcut to an URL.

Step 1: Add the extension namespace

To build on top of the simple setup example, let's re-use the same source file and add the following:

<?xml version='1.0'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>
   <Product Id='PUT-GUID-HERE' Name='Test Package' Language='1033'
             Version='1.0.0.0' Manufacturer='Microsoft Corporation'>
      <Package Description='My first Windows Installer package'
               Comments='This is my first attempt at creating a Windows Installer database'
               Manufacturer='Microsoft Corporation' InstallerVersion='200' Compressed='yes' />
 
      <Media Id='1' Cabinet='product.cab' EmbedCab='yes' />
 
      <Directory Id='TARGETDIR' Name='SourceDir'>
         <Directory Id='ProgramFilesFolder' Name='PFiles'>
            <Directory Id='MyDir' Name='Test Program'>
               <Component Id='MyComponent' Guid='PUT-GUID-HERE'>
                  <File Id='readme' Name='readme.txt' DiskId='1' Source='readme.txt' />
               </Component>
 
               <Merge Id='MyModule' Language='1033' SourceFile='module.msm' DiskId='1' />
            </Directory>
         </Directory>
      </Directory>
 
      <Feature Id='MyFeature' Title='My 1st Feature' Level='1'>
         <ComponentRef Id='MyComponent' />
         <MergeRef Id='MyModule' />
      </Feature>
   </Product>
</Wix>

Step 2: Author the element to create the shortcut

Add the following to the source file::

<?xml version='1.0'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>
   <Product Id='PUT-GUID-HERE' Name='Test Package' Language='1033'
             Version='1.0.0.0' Manufacturer='Microsoft Corporation'>
      <Package Description='My first Windows Installer package'
               Comments='This is my first attempt at creating a Windows Installer database'
               Manufacturer='Microsoft Corporation' InstallerVersion='200' Compressed='yes' />
 
      <Media Id='1' Cabinet='product.cab' EmbedCab='yes' />
 
      <Directory Id='TARGETDIR' Name='SourceDir'>
         <Directory Id='ProgramFilesFolder' Name='PFiles'>
            <Directory Id='MyDir' Name='Test Program'>
               <Component Id='MyComponent' Guid='PUT-GUID-HERE'>
                  <File Id='readme' Name='readme.txt' DiskId='1' Source='readme.txt' />
                  <util:InternetShortcut Id='Bing' Name='Bing' Target='http://www.bing.com'/>
               </Component>
 
               <Merge Id='MyModule' Language='1033' SourceFile='module.msm' DiskId='1' />
            </Directory>
         </Directory>
      </Directory>
 
      <Feature Id='MyFeature' Title='My 1st Feature' Level='1'>
         <ComponentRef Id='MyComponent' />
         <MergeRef Id='MyModule' />
      </Feature>
   </Product>
</Wix>;;;;

Step 3: Build the installer

To build the installer, you need to pass in the extension that the source file is referencing:

C:\test> candle product.wxs -ext WixUtilExtension
Microsoft (R) Windows Installer Xml Compiler version 1.0.1220.15022
Copyright (C) Microsoft Corporation 2003. All rights reserved
 
product.wxs
 
C:\test> light product.wixobj -ext WixUtilExtension
Microsoft (R) Windows Installer Xml Linker version 1.0.1220.15022
Copyright (C) Microsoft Corporation 2003. All rights reserved