Create a Windows Installer "MSI" using WiX part2

Page updated :

At first

Last time, we prepared the necessary files and set up the project. This time, "Product.wxs" is edited and various settings of the installer are performed.

Edit installation settings (Product.wxs)

The contents of the Product.wxs file are written in XML format. There are a lot of parameters, but first, we'll make the minimum settings to make sure that the installer can be created. If you want to set up more detailed, please refer to a separate article or the official site.

At the time of creation of the project, the following code is:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="SetupLittleSaviorTrial_x86" Language="1033" Version="1.0.0.0" Manufacturer="" UpgradeCode="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate />

    <Feature Id="ProductFeature" Title="SetupLittleSaviorTrial_x86" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
    </Feature>
  </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="SetupLittleSaviorTrial_x86" />
      </Directory>
    </Directory>
  </Fragment>

  <Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
      <!-- <Component Id="ProductComponent"> -->
      <!-- TODO: Insert files, registry keys, and other resources here. -->
      <!-- </Component> -->
    </ComponentGroup>
  </Fragment>
</Wix>

Here's what you need to change. Add tags and attributes that do not exist.

Wix/Product/@Id

Sets the GUID that identifies the application.

There are a number of tools for generating GUIDs, but it's quick to use the tools that come with Visual Studio. Select the "Tools" menu and "Create GUID".

image

Get a 36-digit code, including a hyphen, and set it to Wix/Product/@Id.

<Wix>
  <Product Id="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" />

Wix/Product/@Name

The name of the application that appears at each part of the installer screen. It is also the name that appears in the Add or remove programs list.

<Wix>
  <Product Name="リトルセイバー 体験版" />

image

image

Wix/Product/@Manufacturer

Enter the name of the manufacturer. Appears in the author of the installer or the publisher of the program list.

<Wix>
  <Product Manufacturer="ソーサリーフォース">

image

image

Wix/Product/UIRef/@Id

Enter the ID that identifies what screen the installation wizard displays. This time, because it is the minimum configuration to install to display only license, "WixUI_Minimal" is specified.

<Wix>
  <Product>
    <UIRef Id="WixUI_Minimal" />

I think that the following site will be helpful what kind of specification can be specified.

Using the WixUI Dialog Set

Wix/Product/WixVariable/*

Specify the file to use in the wizard UI. The minimum configuration uses three files: The value of the Id is fixed and the value is specified in Value.

<Wix>
  <Product>
    <WixVariable Id="WixUILicenseRtf" Value="license.rtf" />
    <WixVariable Id="WixUIDialogBmp" Value="dialog.bmp" />
    <WixVariable Id="WixUIBannerBmp" Value="banner.bmp" />

Application icon for installation

Used for application icons that appear, such as Add or remove programs.

In the "SourceFile" of the Icon element, specify the ico file as the path relative to the project folder.

"Property Id="ARPPRODUCTICON" is the icon association definition.

<Wix>
  <Product>
    <Icon Id="LITTLESAVIOR.ICO" SourceFile="LittleSaviorTrial\LittleSavior.ico" />
    <Property Id="ARPPRODUCTICON" Value="LITTLESAVIOR.ICO" />

Wix/Fragment (file folder configuration)

Set the folder configuration to which you want to install. You will also place the file, but you will create only a folder first.

The value of "Name" set to "Id="ProgramMenuDir" is the name of the folder placed on the start menu shortcut. Set the Guid, too.

<Wix>
  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="SetupLittleSaviorTrial_x86" />
      </Directory>
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ProgramMenuDir" Name="リトルセイバー 体験版">
          <Component Id="ProgramMenuDir" Guid="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX">
            <RemoveFolder Id="ProgramMenuDir" On="uninstall" />
            <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" />
          </Component>
        </Directory>
      </Directory>
    </Directory>
  </Fragment>

Add installation files

You can also manually add it to the Product.wxs file. Because a GUID is needed for a file, it is difficult to work when the number of files increases. So we'll add files using WixEdit.

Start WixEdit.

image

Open product.wxs file.

image

image

Select Files from the icon on the left. Delete the folder slower in ProgramFilesFolder.

image

Right-click the ProgramFilesFolder folder and select Import Folder.

image

Select the folder where you want to install the files.

image

A set of files is added to the tree.

image

To associate with other parameters, select the folder you added and re-set "Id" to "INSTALLFOLDER".

image

Create a shortcut for the Start menu. Select "New" or "Shortcut" from the right-click menu of the exe file.

image

Select when shortcut is added and right-click the blank to add the property.

image

Add the following parameters: (Please correct the unique name to match the program.)

Attribute value
Id LITTLE SAVIORTRIAL. EXE_shortcut
Name Little Saber Trial
Directory ProgramMenuDir
WorkingDirectory INSTALLDIR
Icon LITTLE SAVIOR. Ico
IconIndex 0
Advertise Yes

image

Then select the Feature tab, right-click ProductFeature and select Select Components to add.

image

Select all.

image

Has been added.

image

Save it.

image

Product.wxs should look like this:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" Name="リトルセイバー 体験版" Language="1033" Version="1.0.0.0" Manufacturer="ソーサリーフォース" UpgradeCode="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate />
    <UIRef Id="WixUI_Minimal" />
    <WixVariable Id="WixUILicenseRtf" Value="license.rtf" />
    <WixVariable Id="WixUIDialogBmp" Value="dialog.bmp" />
    <WixVariable Id="WixUIBannerBmp" Value="banner.bmp" />
    <Icon Id="LITTLESAVIOR.ICO" SourceFile="LittleSaviorTrial\LittleSavior.ico" />
    <Property Id="ARPPRODUCTICON" Value="LITTLESAVIOR.ICO" />
    <Feature Id="ProductFeature" Title="SetupLittleSaviorTrial_x86" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
      <ComponentRef Id="LITTLESAVIOR.ICO" />
      <ComponentRef Id="LITTLESAVIORTRIAL.EXE" />
      <ComponentRef Id="LITTLESAVIORTRIAL.EXE.CONFIG" />
      <ComponentRef Id="ProgramMenuDir" />
    </Feature>
    <UI />
  </Product>
  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="LittleSaviorTrial">
          <Component Id="LITTLESAVIOR.ICO" DiskId="1" Guid="0B4DD82C-C6EF-4299-8EAB-4F9BB35FD952">
            <File Id="LITTLESAVIOR.ICO" Name="LittleSavior.ico" Source="LittleSaviorTrial\LittleSavior.ico" />
          </Component>
          <Component Id="LITTLESAVIORTRIAL.EXE" DiskId="1" Guid="8D805936-A25E-4DA6-9A0A-A5BDB2AD768D">
            <File Id="LITTLESAVIORTRIAL.EXE" Name="LittleSaviorTrial.exe" Source="LittleSaviorTrial\LittleSaviorTrial.exe" KeyPath="yes">
              <Shortcut Id="LITTLESAVIORTRIAL.EXE_shortcut" Name="リトルセイバー 体験版" Directory="ProgramMenuDir" WorkingDirectory="INSTALLDIR" Icon="LITTLESAVIOR.ICO" IconIndex="0" Advertise="yes" />
            </File>
          </Component>
          <Component Id="LITTLESAVIORTRIAL.EXE.CONFIG" DiskId="1" Guid="790C427A-A72C-4444-ACD6-ECF32AA788AD">
            <File Id="LITTLESAVIORTRIAL.EXE.CONFIG" Name="LittleSaviorTrial.exe.config" Source="LittleSaviorTrial\LittleSaviorTrial.exe.config" />
          </Component>
        </Directory>
      </Directory>
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ProgramMenuDir" Name="リトルセイバー 体験版">
          <Component Id="ProgramMenuDir" Guid="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX">
            <RemoveFolder Id="ProgramMenuDir" On="uninstall" />
            <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" />
          </Component>
        </Directory>
      </Directory>
    </Directory>
  </Fragment>
  <Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
    </ComponentGroup>
  </Fragment>
</Wix>

Build and run confirmation

In Visual Studio, make the solution configuration Release.

image

Start the build from Build Solution.

image

An msi file is generated in the bin\Release folder when the building is successful.

image

The installer starts when you try to run it.

image

When the installation is complete, a shortcut is created in the Start menu.

image

The files are placed in the Program Files (x86) folder.

image

The application also appears in Programs and Features.

image

Run the application and make sure it is working properly.

image

Summary

This section showed you how to create an MSI installer using Visual Studio and WiX. I would like to explain the detailed settings in a separate article.