如何将文件安装到合并模块中的 Public 文档?

How to install files to Public Documents in merge module?

我需要将一些文件从我的合并模块安装到 Public 文档。我正在尝试使用 WIX_DIR_COMMON_DOCUMENTS 属性,但所有文件都安装到 Program Files。

这是我的合并模块源代码:

<PropertyRef Id="WIX_DIR_COMMON_DOCUMENTS" />

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="MergeRedirectFolder">
    <Directory Id="MirProgramFolder" Name="Data">
      <Component Id="cmpData" Guid="c64db3df-1bf3-4c03-8b69-ac1adbb8bfdd">
        <File Id="filData" Source="ForProgramFiles.txt"/>
      </Component>
    </Directory>
  </Directory>

  <!-- Files to install to public documents folder -->
  <Directory Id="WIX_DIR_COMMON_DOCUMENTS">
    <Directory Id="MirCommonDocumentsFolder" Name="MIR">
      <Component Id="cmpTest" Guid="22381726-2cf0-45f0-a9a8-9703ed456ed6">
        <File Id="filTest" Source="ForPublicDocs.txt"/>
      </Component>
    </Directory>
  </Directory>
</Directory>

这是我的安装项目源代码:

<Product Id="*" Name="SetupProject1" Language="1033" Version="1.0.0.0" Manufacturer="Slava Antonov" UpgradeCode="7418b1ee-fb1e-4000-995f-4cff646346c5">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

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

    <Feature Id="ProductFeature" Title="SetupProject1" Level="1">
  <MergeRef Id="MergeModule1"/>
    </Feature>
</Product>

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="SetupProject1" />
        </Directory>
    </Directory>
</Fragment>

<Fragment>
<DirectoryRef Id="INSTALLFOLDER">
  <Merge Id="MergeModule1" SourceFile="$(var.MergeModule1.TargetDir)MergeModule1.msm" DiskId="1" Language="1033"/>
</DirectoryRef>
</Fragment>

为什么 WIX_DIR_COMMON_DOCUMENTS 在合并模块中不起作用?

原因

当您在合并模块源中写入 <Directory Id="WIX_DIR_COMMON_DOCUMENTS"> 时,WiX 将 模块化 目录 ID 以防止与使用合并的产品中的任何现有目录 ID 发生冲突模块。

您可以通过在 Orca 或 InstEd(推荐)中打开 MSM 文件来验证这一点,然后查看 Directory table。您将看到类似 WIX_DIR_COMMON_DOCUMENTS.9FE2C761_1860_4D8C_8538_352164BDC12F 的目录 ID。附加的 GUID 是合并模块 ID。

不幸的是,自定义操作WixQueryOsDirs只设置了属性 WIX_DIR_COMMON_DOCUMENTS,而不是使用模块化目录ID,因此模块化目录ID仍将指向程序文件目录。

解决方案

像这样抑制 WIX_DIR_COMMON_DOCUMENTS 的模块化:

<PropertyRef Id="WIX_DIR_COMMON_DOCUMENTS"/>
<Property Id="WIX_DIR_COMMON_DOCUMENTS" SuppressModularization="yes"/>

在构建使用合并模块的设置时,当此设置已经引用 WIX_DIR_COMMON_DOCUMENTS 或 WixUtilExtension 中的其他目录时,您可能会收到一些警告。这些可以安全地忽略。

E. G。在我的实验中,我收到了这些警告:

C:\Users\REDACTED\source\repos\SetupProject1\SetupProject1\Product.wxs(38,0): warning LGHT1056: The Directory table contains a row with primary key(s) 'WIX_DIR_COMMON_DOCUMENTS' which cannot be merged from the merge module 'C:\Users\REDACTED\source\repos\SetupProject1\MergeModule1\bin\Debug\MergeModule1.msm'.  This is likely due to collision of rows with the same primary key(s) (but other different values in other columns) between the database and the merge module.
C:\Users\REDACTED\source\repos\SetupProject1\SetupProject1\Product.wxs(38,0): warning LGHT1055: The InstallUISequence table contains an action 'WixQueryOsDirs' which cannot be merged from the merge module 'C:\Users\REDACTED\source\repos\SetupProject1\MergeModule1\bin\Debug\MergeModule1.msm'.  This action is likely colliding with an action in the database that is being created.  The colliding action may have been authored in the database or merged in from another merge module.  If this is a standard action, it is likely colliding due to a difference in the condition for the action in the database and merge module.  If this is a custom action, it should only be declared in the database or one merge module.
C:\Users\REDACTED\source\repos\SetupProject1\SetupProject1\Product.wxs(38,0): warning LGHT1055: The InstallExecuteSequence table contains an action 'WixQueryOsDirs' which cannot be merged from the merge module 'C:\Users\REDACTED\source\repos\SetupProject1\MergeModule1\bin\Debug\MergeModule1.msm'.  This action is likely colliding with an action in the database that is being created.  The colliding action may have been authored in the database or merged in from another merge module.  If this is a standard action, it is likely colliding due to a difference in the condition for the action in the database and merge module.  If this is a custom action, it should only be declared in the database or one merge module.
C:\Users\REDACTED\source\repos\SetupProject1\SetupProject1\Product.wxs(38,0): warning LGHT1056: The CustomAction table contains a row with primary key(s) 'WixQueryOsDirs' which cannot be merged from the merge module 'C:\Users\REDACTED\source\repos\SetupProject1\MergeModule1\bin\Debug\MergeModule1.msm'.  This is likely due to collision of rows with the same primary key(s) (but other different values in other columns) between the database and the merge module.
C:\Users\REDACTED\source\repos\SetupProject1\SetupProject1\Product.wxs(38,0): warning LGHT1056: The Property table contains a row with primary key(s) 'SecureCustomProperties' which cannot be merged from the merge module 'C:\Users\REDACTED\source\repos\SetupProject1\MergeModule1\bin\Debug\MergeModule1.msm'.  This is likely due to collision of rows with the same primary key(s) (but other different values in other columns) between the database and the merge module.

因此 WiX 告诉我们它无法导入属性 WIX_DIR_COMMON_DOCUMENTSSecureCustomProperties 和自定义操作 WixQueryOsDirs,因为它们已经存在于主产品中。这没什么好担心的,因为合并模块的组件会愉快地使用现有的 属性 WIX_DIR_COMMON_DOCUMENTS.