Tuesday, August 5, 2008

Creating a .msi file using Windows Installer XML (WiX)

The Windows Installer XML (WiX) platform is a set of tools and specifications that allow you to easily create Windows Installer database files. The WiX tools model the traditional compile and link model used to create executables from source code. For WiX, source code is written in XML files. These files are validated against a schema, wix.xsd and then processed by a preprocessor, compiler, and linker to create the desired result.

The latest version is available as free download from this location.

In this post I will explain how to use WIX to create an installation package file (.msi) for a web application using Visual Studio 2008.

  • Create a new WiX project in Visual Studio IDE by selecting WIX Project from the list and click on new project.
  • Open the Product.wxs file created as part of the project and change the required field values (ProductName, Manufacturer etc)

    <Product Id="YOUR GUID - 944B15CA-A13A-4d39-94AC-6599633A7C84" Name="YourWebsite" Language="1033" Version="1.0.0.0" Manufacturer="Your Name" UpgradeCode=" YOUR GUID - 40B2FF80-88DD-48fc-A081-1F6AD4E52BA0">

  • In the Product.wxs file replace the section where you find the comment


    With the names of the components you need to deploy into your folder.
    E.g.
    <
    Directory Id="InstallDir" Name="Your Folder Name">
    <Component Id="DefaultPage" Guid="6CEFE537-A4BE-4c67-8C20-86F6E0CC8240">
    <File Id="MyDefaultPage" Source="..\Default.aspx" DiskId="1">File>
    Component>

  • Add Xml schema definition for IISExtensions to the Product.wxs file

    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">

  • To generate the GUID for each component use the Tools->Create Guid option from Visual Studio.

  • Copy the generated GUID and paste that to the relevant section.

  • If you need to move your assemblies into the Bin folder you need to create another directory structure under the main folder.

    <Component Id="DefaultPage" Guid="6CEFE537-A4BE-4c67-8C20-86F6E0CC8240">

    <File Id="MyDefaultPage" Source="..\Default.aspx" DiskId="1">File>

    Component>

    <Directory Id="YourProjectBin" Name="Bin">

  • Add sections for assemblies to be deployed in the Bin directory

    <Directory Id="YourProjectBin" Name="Bin">

    <Component Id="YourProjectAssembly" Guid="PAF675GF-9087-4661-88GH-5GH48388HJK2">

    <File Id=" YourProjectAssemblyDll" Source="..\Bin\SellKeys. YourProjectAssembly.dll" DiskId="1">File>

    Component>

  • If you need to deploy the assemblies into GAC you need to configure additional parameters like KeyPath and Assembly.

  • Create a section to describe the virtual directory structure for the application.

    <Component Id='YourProjectVirtualDirComponent' Guid='C2F09A52-3DF0-41b9-8B2E-BC8B092AF2AB'>

    <iis:WebVirtualDir Id='YourProjectVirtualDir' Alias='Your Virtual Dricetory Name' Directory='InstallDir' WebSite='DefaultWebSite'>

    <iis:WebApplication Id='YourWebApplication' Name='Your Application Name' />

    iis:WebVirtualDir>

    Component>

    Add section for the path of Virtual directory.

    <iis:WebSite Id='DefaultWebSite' Description='Default Web Site'>

    <iis:WebAddress Id='AllUnassigned' Port='80' />

    iis:WebSite>

  • Make changes to the Feature section to add ComponentRef to all the components in the previous sections.

    <Feature Id="ProductFeature" Title="Your Application" Level="1">

    <ComponentRef Id=" DefaultPage" />

    <ComponentRef Id=" YourProjectAssembly" />

    Feature>

  • Add a reference to the WIXIIsExtension to the project.

  • Build the project to generate the .msi file.

1 comment:

Anonymous said...

Nvin Installer is a simple installer developed using WiX toolset. It is really useful if somebody don't want scratch their head to create MSI files.