WiXでのインストーラ作成テスト

WiXWindows用の簡単なインストーラを作成する。

準備するファイル

wxsファイル(ファイル名はtestwix.wxs)を以下のようにする。
参考サイト:http://www.softark.net/wix/lesson01.html

<?xml version='1.0' encoding='utf-8'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
  <?define PN="HogeSoftware-1.0.0" ?>

  <Product Name='$(var.PN)'
           Id='f75821ea-4332-4ccb-a79e-97f0f9dfd24b'
           UpgradeCode='1255d0d6-2b8d-4e34-9a4a-926605384aa5'
           Language='1041' Codepage='932'
           Version='1.0.0' Manufacturer='Hoge Inc.'>

    <Package Id='*' Keywords='HogeSoft Installer'
             Description="HogeSoft Installer"
             Comments='nothing'
             Manufacturer='Hoge Inc.' InstallerVersion='100'
             Languages='1041' Compressed='yes' SummaryCodepage='932' />

    <Media Id='1' Cabinet='HogeSoft.cab' EmbedCab='yes' 
           DiskPrompt='DVD-ROM [1]' />
    <Property Id='DiskPrompt' Value="HogeSoft Installer [1]" />

    <Directory Id='TARGETDIR' Name='SourceDir'>
      <Directory Id='ProgramFilesFolder' Name='PFiles'>
         <Directory Id='HogeInc' Name='HogeInc'>
           <Directory Id='INSTALLDIR' Name='$(var.PN)'>

             <Component Id='MainExecutable'
                       Guid='197f8c1d-c864-4016-b89f-5ed7d4256818'>
               <File Id='HOGEEXE'
                     Name='hoge.exe' DiskId='1'
                     Source='hoge.exe' KeyPath='yes'>
                 <Shortcut Id="startmenuHOGE" Directory="ProgramMenuDir"
                           Name="$(var.PN)" WorkingDirectory='INSTALLDIR'
                           Icon="hoge.exe" IconIndex="0" Advertise="yes" />
                 <Shortcut Id="desktopHOGE" Directory="DesktopFolder"
                           Name="$(var.PN)" WorkingDirectory='INSTALLDIR'
                           Icon="hoge.exe" IconIndex="0" Advertise="yes" />
              </File>
            </Component>

            <Component Id='Manual'
                       Guid='01a48e35-40fc-4891-b5e7-7771fe189694'>
              <File Id='Manual' Name='Manual.pdf' DiskId='1'
                    Source='Manual.pdf' KeyPath='yes'>
                <Shortcut Id='startmenuManual' Directory='ProgramMenuDir'
                          Name='Manual' Advertise='yes' />
              </File>
            </Component>
            
          </Directory>
        </Directory>
      </Directory>

      <Directory Id="ProgramMenuFolder" Name="Programs">
        <Directory Id="ProgramMenuDir" Name="$(var.PN)">
          <Component Id="ProgramMenuDir"
                     Guid="c8bfe633-6f6f-4a6f-83f9-c1e415f75962">
            <RemoveFolder Id='ProgramMenuDir' On='uninstall' />
            <RegistryValue Root='HKCU'
                           Key='Software\[Manufacturer]\[ProductName]'
                           Type='string' Value='' KeyPath='yes' />
          </Component>
        </Directory>
      </Directory>
      <Directory Id="DesktopFolder" Name="Desktop" />

    </Directory>

    <Feature Id='Complete' Title='HogeSoftware 1.0.0'
             Description='Complete package' Display='expand'
             Level='1' ConfigurableDirectory='INSTALLDIR'>
      <Feature Id='MainProgram' Title='Program'
               Description='Main program' Level='1'>
        <ComponentRef Id='MainExecutable' />
        <ComponentRef Id='ProgramMenuDir' />
      </Feature>

      <Feature Id='Documentation' Title='Manual'
               Description='Manual' Level='1'>
        <ComponentRef Id='Manual' />
      </Feature>

    </Feature>

    <Icon Id="hoge.exe" SourceFile="hoge.exe" />

    <UIRef Id="WixUI_FeatureTree" />
    <UIRef Id="WixUI_ErrorProgressText" />
    <WixVariable Id="WixUILicenseRtf" Value="release\License.rtf" />
  </Product>
</Wix>

ビルドを簡単に行うために、スクリプトを以下の通りに書いておく。ファイル名は任意でよいが、build.cmdとしている。一度作成しておくと、使いまわしができる。
参考サイト:WiXではじめるWindows Installer作成入門 第2回 (1/3):CodeZine(コードジン)

@ECHO OFF
REM check parameters
IF "%1" == "" GOTO ARG_ERR
IF NOT EXIST "%1" GOTO ARG_ERR
REM set variables to be local
SETLOCAL

REM set WIXDIR as environment variable
IF "%WIXDIR%" == "" SET WIXDIR=C:\WIX35

REM create holders
IF NOT EXIST Obj\. MD Obj
IF NOT EXIST Bin\. MD Bin

REM split file name
SET FNAME=%~n1

REM compile
%WIXDIR%\CANDLE.EXE %FNAME%.wxs -out Obj\
IF ERRORLEVEL 1 GOTO BLD_ERR

REM link
%WIXDIR%\LIGHT.EXE -ext WixUIExtension Obj\%FNAME%.wixobj -out Bin\%FNAME%.msi
IF ERRORLEVEL 1 GOTO BLD_ERR

ECHO complete build
GOTO END

REM postprocess
:ARG_ERR
ECHO cannot find file
GOTO END
:BLD_ERR
ECHO error occurs while building
:END

これらファイルと、インストールするファイル(実行モジュール等)を用意し、下のように同じフォルダに置いておく。

release/フォルダの中には、ライセンス条項を記したファイルを置いておく。ここでのファイル名は、License.rtfとしている。ファイル形式はrtfにする。

ビルドする


コマンドプロンプトで、ビルドする。


Bin/フォルダが作成され、その中にtestwix.msiができている。これをダブルクリックするとインストールが始まる。

インストールの実行


インストーラ起動画面


その次に、License agreementの画面になる。


その次に、インストールするものの選択や、インストールディレクトリの変更ができる。


インストール開始。


インストール中。


インストール完了を告げる画面。


Windowsの「スタート」メニューから「すべてのプログラム」を見ると、確かにインストールされていることが分かる。


もう一度、インストーラを起動すると、この画面になる。再インストール、インストールしたものを削除することができる。