wix - 安装到不同位置但引用相同组件的功能部件

标签 wix wix3

我有一个包含多种功能的产品,这些功能可以安装到不同的位置,例如功能 1 是安装在 Program Files 中的可执行文件,功能 2 是安装在 wwwroot 中的网站。然而,功能 1 和功能 2 都依赖于许多相同的 dll,因此需要将包含这些 dll 的组件安装在 2 个不同的位置,具体取决于安装的功能。

有没有办法在不定义每个组件两次的情况下实现这一目标?

为了提供我想要实现的更完整的示例,可以使用以下方法编译以下完整的 wxs 文件:

> 蜡烛.exe Foobar.wxs

> light.exe -ext WixUIExtension Foobar.wixobj

> msiexec/i Foobar.msi

<?xml version='1.0' encoding='windows-1252'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>

  <Product Name='Foobar 1.0' 
           Id='E578DF12-DDE7-4BC2-82CD-FF11862862D5' 
           UpgradeCode='90F09DD5-E01B-4652-8971-515997730195'
           Language='1033' 
           Codepage='1252' 
           Version='1.0.0' 
           Manufacturer='Acme Ltd.'>

    <Package Id='*' 
             Keywords='Installer'
             Description="Acme 1.0 Installer"
             InstallerVersion='100' 
             Languages='1033' 
             Compressed='yes' 
             SummaryCodepage='1252' />

    <Media Id='1' Cabinet='Sample.cab' EmbedCab='yes' DiskPrompt="CD-ROM #1" />
    <Property Id='DiskPrompt' Value="Acme 1.0 Installation" />

    <Directory Id='TARGETDIR' Name='SourceDir'>
         <!-- Directory 1 (Program Files) -->
        <Directory Id="ProgramFilesFolder" Name="PFiles">
            <Directory Id="PROGRAM_INSTALLDIR" Name="Acme" />
        </Directory>

        <!-- Directory 2 (wwwroot) -->
        <Directory Id="Inetpub" Name="Inetpub">
            <Directory Id="wwwroot" Name="wwwroot">
                <Directory Id="WEBSITE_INSTALLDIR" Name="AcmeWebSite" />
            </Directory>
        </Directory>
    </Directory>

    <DirectoryRef Id='PROGRAM_INSTALLDIR'>
        <Component Id="Component1" Guid="79EC9E0B-8325-427B-A865-E1105CB16B62">
            <File Id="File1" Name="File1.txt" Source="File1.txt" />
        </Component>
    </DirectoryRef>

    <DirectoryRef Id='WEBSITE_INSTALLDIR'>
        <Component Id="Component2" Guid="702E6573-8FBC-4269-A58D-FD1157111F0F">
            <File Id="File2" Name="File2.txt" Source="File2.txt" />
        </Component>
    </DirectoryRef>

    <Feature Id="Feature.Program" 
             Title="My Program" 
             TypicalDefault="install" 
             Level="1" 
             ConfigurableDirectory="PROGRAM_INSTALLDIR" >
        <ComponentRef Id="Component1"/>
        <ComponentRef Id="Component2"/>
    </Feature>

    <Feature Id="Feature.Website" 
             Title="My Website" 
             TypicalDefault="install" 
             Level="1" 
             ConfigurableDirectory="WEBSITE_INSTALLDIR" >
        <ComponentRef Id="Component1"/>
        <ComponentRef Id="Component2"/>
    </Feature>

    <UIRef Id="WixUI_Mondo" />
    <UIRef Id="WixUI_ErrorProgressText" />

  </Product>
</Wix>

然而,这将导致只有 File1.txt 被安装在

C:\Program Files (x86)\Acme

并且只有 File2.txt 被安装在

_C:\Inetpub\wwwroot\AcmeWebsite_

一种解决方案是两次定义组件,例如:
<DirectoryRef Id='PROGRAM_INSTALLDIR'>
    <Component Id="Component1" Guid="79EC9E0B-8325-427B-A865-E1105CB16B62">
        <File Id="File1" Name="File1.txt" Source="File1.txt" />
    </Component>
    <Component Id="Component2" Guid="702E6573-8FBC-4269-A58D-FD1157111F0F">
        <File Id="File2" Name="File2.txt" Source="File2.txt" />
    </Component>
</DirectoryRef>

<DirectoryRef Id='WEBSITE_INSTALLDIR'>
    <Component Id="Component1.Web" Guid="397E93AA-32FB-425A-A783-386E0CCA2357">
        <File Id="File1.Web" Name="File1.txt" Source="File1.txt" />
    </Component>
    <Component Id="Component2.Web" Guid="5C3AFF06-3623-4524-A90B-72B46DE5572A">
        <File Id="File2.Web" Name="File2.txt" Source="File2.txt" />
    </Component>
</DirectoryRef>

<Feature Id="Feature.Program" 
         Title="My Program" 
         TypicalDefault="install" 
         Level="1" 
         ConfigurableDirectory="PROGRAM_INSTALLDIR" >
    <ComponentRef Id="Component1"/>
    <ComponentRef Id="Component2"/>
</Feature>

<Feature Id="Feature.Website" 
         Title="My Website" 
         TypicalDefault="install" 
         Level="1" 
         ConfigurableDirectory="WEBSITE_INSTALLDIR" >
    <ComponentRef Id="Component1.Web"/>
    <ComponentRef Id="Component2.Web"/>
</Feature>

但是,如果我们添加要安装在另一个位置的第三个功能,会发生什么?那么我们是否必须再次重新定义每个组件?拥有 100 多个组件,管理重复的组件将成为一项艰巨的任务。

有什么建议?

最佳答案

您在 Windows 安装程序中看到了一个限制。一个组件只能通过 MSI 安装一次。每个组件只能安装到一个目录。要将组件的内容安装到两个不同的位置,您必须创建另一个具有相同内容的组件,或者尝试使用 CopyFile 元素复制内容。

可能不是您想听到的,但这就是 Windows Installer 的工作方式。

幸运的是,如果您选择使用选项 1,那么 WiX 工具集只会在组件间压缩重复的内容一次。 Smart cabbing rocks!

关于wix - 安装到不同位置但引用相同组件的功能部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4941602/

相关文章:

windows-vista - 为什么 Windows Vista x64 上的 x86 WiX 安装程序不会将 key 写入注册表中的 Wow6432Node?

WiX - 安装程序忽略我的 "perUser"安装范围。为什么?

installation - 运行 RemovePreviousVersion 时,MSI 不会安装所有文件

installation - 从命令行传递的 WiX 条件属性不起作用?

wix - 检查 wix Bootstrapper RegistrySearch bal :Condition only at time of installation

iis - 在安装 Web 应用程序 IIS 期间添加脚本映射

wpf - 使用 WiX Bootstrap ,如果我添加数字签名,安装程序将无法工作

wix - 此 Windows 安装程序包有问题。无法运行完成此安装所需的程序

dialog - WiX 标准对话

Wix 无法解析符号 "Icon"