WiX - Set Merge Module Directory at Install Time?
我已经按照位于以下位置的入门Wix指南中的说明创建了一个合并模块:http://wix.sourceforge.net/manual-wix2/authoring_merge_modules.htm。
这是合并模块wxs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <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的主要产品:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <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中选择的目录。无论如何,它们都进入" [程序文件] \\\\\\\\ SomeCompany Technologies \\\\\\\\ Some Repository \\\\"目录。
如果我从合并模块目录路径中删除对Program Files的引用,并使用名称为"。"的根目录来拾取父MSI的父目录,则合并模块将选择所选的用户目录就好了。但是随后,Visual Studio在构建时抛出错误,即无法进行收集,因为该路径必须植根于标准目录之一才能使用自动生成的Guid。
那么我如何才能使合并模块采用安装时用户选择的目录,同时仍将合并模块路径保留在标准目录中?
您对MSI感到困惑,因为ProgramFilesFolder是保留的属性名称。将该值更改为" MergeRedirectFolder",并借助Directory元素下具有INSTALLLOCATION ID的Merge元素,MergeRedirectFolder将与INSTALLLOCATION关联。目录Some Repository([MODULEINSTALLLOCATION])将成为INSTALLLOCATION的子目录。
也可以随时在CodePlex上签出ISWIX项目。这对于创作和维护合并模块非常有用,并且具有与您在此处尝试执行的操作相关的示例源代码。