如何使用 Wix 将一组文件复制到多个位置?

问题描述 投票:0回答:3

我正在尝试进行安装,将相同文件的副本放在多个位置...

有没有简单的方法可以做到这一点?

例如。如果我想将 a.txt b.txt c.txt 放入以下所有目录中:-

.\废话\
.\文本\
.\示例\

wix windows-installer
3个回答
14
投票

只需创建引用同一文件的多个组件,但将其安装到不同的位置。唯一的问题是您不能使用两个

<File Source="somefile"/>
元素引用同一文件,因为它们将获得相同的自动生成的 ID。明确为文件元素指定不同的 ID 以避免该问题。

<DirectoryRef Id="directory1">
   <Component Id="somefile-component1">
      <File Id="somefile-id1" Source="/path/to/somefile"/>
   </Component>
</DirectoryRef>

<DirectoryRef Id="directory2">
   <Component Id="somefile-component2">
      <File Id="somefile-id2" Source="/path/to/somefile"/>
   </Component>
</DirectoryRef>

7
投票

重复文件:Windows Installer对此有自己的概念,称为

"DuplicateFiles"
。仅当文件实际上相同时它才有效,但听起来这就是您想要的。

CopyFile Element:在 WIX 中,您可以通过

CopyFile element

实现此操作

http://wix.sourceforge.net/manual-wix2/wix_xsd_copyfile.htm

我还没有真正尝试过,但它应该看起来像这样

<Component Id='Manual' Guid='*' >
  <File Id='Manual' Name='Manual.pdf' Source='Manual.pdf' KeyPath='yes'>
    <CopyFile  Id='MyDuplicateFile1' DestinationProperty ='DesktopFolder'/>
  </File>
</Component>

0
投票

我试图做同样的事情 - 将 2 个文件添加到 6 个不同的文件夹中。 这是我的 Product.wxs 文件:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"><?define MYAPPNAME_TargetDir=$(var.XXXX.TargetDir)?>
    <Product Id="*" Name="MYAPPNAME" Language="1033" Version="1.0.0.0" Manufacturer="" UpgradeCode="d0b7c589-3613-4428-a75e-1d6f73eaeeaf">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />

        <Feature Id="ProductFeature" Title="MYAPPNAME" Level="1">
            <ComponentRef Id="MYADDIN.addin" />
            <ComponentRef Id="MYDLL.dll" />
            <ComponentRef Id="AmyMetom.addin.1" />
            <ComponentRef Id="AmyMetom.dll.1" />
        </Feature>
        <UIRef Id="WixUI_Minimal" />
        <WixVariable Id="WixUILicenseRtf" Value="test.rtf" />
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="CommonAppDataFolder">
                <Directory Id="FIRSTDIR" Name="FIRSTDIR">
                    <Directory Id="SECONDDIR" Name="SECONDDIR">
                        <Directory Id="THIRDDIR" Name="THIRDDIR">
                            <Directory Id="R2019" Name="2019"/>
                            <Directory Id="R2020" Name="2020"/>
                            <Directory Id="R2021" Name="2021"/>
                            <Directory Id="R2022" Name="2022"/>
                            <Directory Id="R2023" Name="2023"/>
                            <Directory Id="R2024" Name="2024"/>
                        </Directory>
                        
                    </Directory>
                </Directory>
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <DirectoryRef Id="R2019">
            <Component Id="MYADDIN.addin" Guid="2b9659bd-a124-4a51-906d-6935f5232868">
                <File Id="MYADDIN.addin" Name="MYADDIN.addin" Source="$(var.MYAPPNAME_TargetDir)MYADDIN.addin" />
            </Component>
            <Component Id="MYDLL.dll" Guid="4f8a21b4-8c2f-4e47-870e-d3a0b567a2c0">
                <File Id="MYDLL.dll" Name="MYDLL.dll" Source="$(var.MYAPPNAME_TargetDir)MYDLL.dll" />
            </Component>
        </DirectoryRef>
        <DirectoryRef Id="R2020">
            <Component Id="MYADDIN.addin.1" Guid="2AFC1914-4EBF-4D9E-96F0-1B9C0BA4CE44">
                <File Id="MYADDIN.addin.1" Name="MYADDIN.addin" Source="$(var.MYAPPNAME_TargetDir)MYADDIN.addin" />
            </Component>
            <Component Id="MYDLL.dll.1" Guid="20499518-0D5D-4973-AD43-959F86A5D831">
                <File Id="MYDLL.dll.1" Name="MYDLL.dll" Source="$(var.MYAPPNAME_TargetDir)MYDLL.dll" />
            </Component>
        </DirectoryRef>
    </Fragment>
</Wix>

还有其他优雅的方法可以完成相同的操作,而不是重复我的 xml 标签 6 次吗?

© www.soinside.com 2019 - 2024. All rights reserved.