0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WiX Toolset v4 最低限のGUI付きインストーラ編

Last updated at Posted at 2023-09-15

ユーザに選択肢を与えないタイプのインストーラ。
必要ない処理はタグごと消せば良い。ついでにFeatureからも消す。

UIを使用するときは以下に注意
  1. wix extension addが事前に必要になる?
  2. 拡張機能を使用する場合はエンコードの指定をしてあげる必要があるため、build時に-culture ja-JPが必要になる
  3. wixタグにxmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui"が必要になる
  4. 使用許諾を変更するときは同ディレクトリにワードパッド等でリッチテキストファイルを作成しておく

インストーラ作成のコマンド

wix extension add -g WixToolset.UI.wixext
wix build hoge.wxs -ext WixToolset.UI.wixext -culture ja-JP

hoge.wxsの中身

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
     xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">

     <!-- Name、Manufacturerは漢字使用OK
          日本語は1041
          perMachineにするとStartupFolderの参照先が`C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup`になる。perUserにすると`C:\Users\(ユーザ名)\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup`になる。
       -->
     <Package
        Name="(アプリ名)"
        UpgradeCode="(自分で用意したGUID①)"
        Language="1041"
        Manufacturer="(会社名)"
        Version="1.0.0"
        Scope = "perMachine"    
        ProductCode="(自分で用意したGUID②)">

        <SummaryInformation Keywords="Installer" />

        <!-- ファイルを1つにまとめ、配布しやすい hoge.msi を作るために必要なおまじない。 -->
        <Media Id="1" Cabinet="app.cab" EmbedCab="yes" />   

        <!-- WiXの本体(?)とも言うべきところ。
             インストールするコンポーネント(StandardDirectoryの奥深くにあるComponentのId)をここで指定。
          -->
        <Feature Id="Complete" Level="1">
            <ComponentRef Id="SoftDir" />
            <ComponentRef Id="SoftDirDesktop" />
            <ComponentRef Id="SoftDirProgramMenu" />
            <ComponentRef Id="SoftDirStartup" />
        </Feature>

        <!-- アイコンは事前にIconタグを書き、Idを作っておく必要がある。
             相対参照は hoge.wxsがあるディレクトリからの相対参照(正確にはCWD)
          -->
        <Icon Id="appicon.ico" SourceFile="(自分で用意したアイコンへの相対参照)" />

        <!-- インストールしたいアプリ本体をProgramFilesにコピーする記述。
             ScopeにperMachineを指定した場合、インストール先として C:\Program Files (x86)\(会社英名)\(アプリ英名) が作成される。
             ProgramFilesFolderは事前定義されているフォルダ。他にもProgramFiles64Folderが使用可能。
             Directoryタグでネストしていけば奥深くまでディレクトリを構築可能。
             相対参照は hoge.wxsがあるディレクトリからの相対参照(正確にはCWD)
          -->
        <StandardDirectory Id="ProgramFilesFolder">
            <Directory Id="ManufactureDir" Name="(会社英名)">
                <Directory Id="SoftDir" Name="(アプリ英名)">

                    <Component Id="SoftDir" Guid="(自分で用意したGUID-当コンポーネント用①)">
                        <File Id="ExeFile" Source="(自分で用意したEXEファイルへの相対参照)" Checksum="yes" />
                        <File Id="IcoFile" Source="appicon.ico" Checksum="yes" />
                        <RemoveFolder Id="SoftDir" On="uninstall" />
                    </Component>

                </Directory>
            </Directory>
        </StandardDirectory>

        <!-- ユーザのデスクトップにショートカットを作成する記述。
             DesktopFolderは事前定義されているフォルダ。
             WorkingDirectoryにはDirectoryのIdを入れること。
             Targetは [] で括ればDirectoryのIdも使用可能。絶対参照にすること。
          -->
        <StandardDirectory Id="DesktopFolder">
            <Component Id="SoftDirDesktop" Guid="(自分で用意したGUID-当コンポーネント用②)">
            <Shortcut Id="ExeFileDesk" Directory="DesktopFolder" Name="(ショートカットファイル名)" WorkingDirectory="SoftDir" Target="[SoftDir]\\(自分で用意したEXEファイル名)" Icon="appicon.ico" />
                <RemoveFolder Id="SoftDirDesktop" On="uninstall" />
            </Component>
        </StandardDirectory>

        <!-- スタートのすべてのアプリにショートカットを作成する記述。
             ProgramMenuFolderは事前定義されているフォルダ。
          -->
        <StandardDirectory Id="ProgramMenuFolder">
            <Component Id="SoftDirProgramMenu" Guid="(自分で用意したGUID-当コンポーネント用③)">
                <Shortcut Id="ExeFileMenu" Directory="ProgramMenuFolder" Name="(ショートカットファイル名)" WorkingDirectory="SoftDir" Target="[SoftDir]\\(自分で用意したEXEファイル名)" Icon="appicon.ico" />
                <RemoveFolder Id="SoftDirProgramMenu" On="uninstall" />
            </Component>
        </StandardDirectory>

        <!-- スタートアップにショートカットを作成する記述。
             StartupFolderは事前定義されているフォルダ。Scope/@Scopeの値によって参照先が変動する。
          -->
        <StandardDirectory Id="StartupFolder">
            <Component Id="SoftDirStartup" Guid="(自分で用意したGUID-当コンポーネント用④)">
                <Shortcut Id="ExeFileStartup" Directory="StartupFolder" Name="(ショートカットファイル名)" WorkingDirectory="SoftDir" Target="[SoftDir]\\(自分で用意したEXEファイル名)" Icon="appicon.ico" />
                <RemoveFolder Id="SoftDirStartup" On="uninstall" />
            </Component>
        </StandardDirectory>

        <!-- WixUI_Minimalを使用する場合はユーザに選択肢を渡さないため、この一行を入れておくだけで十分。
             xmlns:ui="~" の記載と -culture ja-JP を追記することに要注意。
          -->
        <ui:WixUI Id="WixUI_Minimal"/>

        <!-- 使用許諾の内容を変更する場合は、ID=WixUILicenseRtfの値を変更してあげるだけ。
             license.rtfはワードパッド等で作成しておく。
          -->
        <WixVariable Id="WixUILicenseRtf" Value="(自分で用意したRTFファイル名)"/>

    </Package>
</Wix>
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?