http://wix.sourceforge.net/manual-wix2/authoring_merge_modules.htmにある Getting Started Wix ガイドの手順に従ってマージ モジュールを作成しました。
マージ モジュール wxs は次のとおりです。
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Module Id="SomeRepositoryMergeModule" Language="1033" Version="1.0.0.0">
<Package Id="f11e7321-a687-4d53-8be7-21a8ae0721a6" Manufacturer="SomeCompany Technologies" InstallerVersion="200" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="MODULEINSTALLLOCATION" Name="Some Repository">
<Component Id="ServicesHostWindowsService" Guid="257D1FAE-4AFF-4155-BDB8-D81F50E5862B">
<File Id="ServicesHostInstallerExecutable" KeyPath="yes" DiskId="1" Name="WindowsServiceHost.exe" Source="..\WindowsServiceHost\bin\Output_For_Installer\WindowsServiceHost.exe" />
<File Id="ServicesHostConfig" KeyPath="no" DiskId="1" Name="WindowsServiceHost.exe.config" Source="..\WindowsServiceHost\bin\Output_For_Installer\WindowsServiceHost.exe.config" />
<File Id="SomeCompanyCommon" KeyPath="no" DiskId="1" Name="SomeCompany.Common.dll" Source="..\WindowsServiceHost\bin\Output_For_Installer\SomeCompany.Common.dll" />
<File Id="SomeRepositorySqlScript" KeyPath="no" DiskId="1" Name="SomeRepository.sql" Source="..\..\..\..\..\DB\SomeRepository\SomeRepository.sql" />
<File Id="LogConfigXml" KeyPath="no" DiskId="1" Name="log.config.xml" Source="..\WindowsService\log.config.xml" />
<ServiceInstall Id="ServicesHostInstallElement" ErrorControl="normal" Start="auto" Type="ownProcess" Vital="yes"
Name="AServer WindowsService Host"
Description="The windows service responsible for hosting SomeCompany Some Repository's WindowsService."
/>
<ServiceControl Id="ServicesHostController" Name="AServer WindowsService Host" Remove="uninstall" Start="install" Stop="uninstall" Wait="no" />
</Component>
</Directory>
</Directory>
</Directory>
<ComponentGroupRef Id="Product.Generated" /><!-- Harvested by heat -->
</Module>
</Wix>
主な製品 wxs は次のとおりです。
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="SomeCompanyGlobalDir" Name="SomeCompany Technologies">
<Directory Id="INSTALLLOCATION" Name="Some Repository">
<Merge Id='SomeRepositoryPrimaryModule' Language='1033' SourceFile='..\SomeRepositoryMergeModule\bin\Output_For_Installer\SomeRepositoryMergeModule.msm' DiskId='1' />
</Directory>
</Directory>
</Directory>
</Directory>
<Feature Id="ProductFeature" Title="SomeRepositoryStandaloneInstaller" Level="1">
<!-- Note: The following ComponentGroupRef is required to pull in generated authoring from project references. -->
<MergeRef Id="SomeRepositoryPrimaryModule"/>
</Feature>
<UIRef Id="WixUI_InstallDir" />
<UIRef Id="WixUI_ErrorProgressText" />
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLLOCATION" />
インストーラーをビルドして実行すると、マージ モジュールのファイルが、ユーザーがインストーラー UI で選択したディレクトリに移動しません。いずれにせよ、それらは「[Program Files]\SomeCompany Technologies\Some Repository\」ディレクトリに入ります。
マージ モジュールのディレクトリ パスから Program Files への参照を削除し、"." という名前のルート ディレクトリを使用するとします。親 MSI の親ディレクトリを取得するには、マージ モジュールがユーザーが選択したディレクトリを適切に取得します。ただし、自動生成された Guid を使用するには、パスが標準ディレクトリのいずれかにルートされている必要があるため、Visual Studio はビルド時にハーベストが機能しないというエラーをスローします。
では、マージ モジュールのパスを標準ディレクトリにルートしたまま、インストール時にユーザーが選択したディレクトリをマージ モジュールに取得させるにはどうすればよいでしょうか?