WiX - 在安装时设置合并模块目录?

时间:2012-05-24 17:32:37

标签: wix wix3.5 merge-module

我已根据位于http://wix.sourceforge.net/manual-wix2/authoring_merge_modules.htm的“入门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的父目录然后合并模块选择用户选择的目录就好了。但是Visual Studio会在构建时抛出错误,因为路径必须植根在其中一个标准目录中才能使用自动生成的Guid。

那么如何让合并模块在安装时获取用户选择的目录,同时仍然将合并模块路径保持在标准目录中?

1 个答案:

答案 0 :(得分:6)

您混淆MSI,因为ProgramFilesFolder是保留的属性名称。将该值更改为&#34; MergeRedirectFolder&#34;并且凭借ID为INSTALLLOCATION的Directory元素下的Merge元素,MergeRedirectFolder将与INSTALLLOCATION关联。然后,目录Some Repository([MODULEINSTALLLOCATION])将成为INSTALLLOCATION的子目录。

也可以随时查看CodePlex上的ISWIX项目。它对编写和维护合并模块非常有用,并且示例源代码与您在此处尝试的内容相关。