You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Wix框架:如何为所有harvest生成的文件设置SharedDllRefCount="yes"

WiX合并模块Harvest生成组件添加SharedDllRefCount属性解决方案

方案1:直接在HarvestDirectory配置中添加全局组件属性(推荐)

你可以直接在.wixproj的HarvestDirectory节点内添加ComponentProperties子元素,为所有harvest自动生成的Component统一设置属性,修改后的配置如下:

<ItemGroup>
    <HarvestDirectory Include="$(HarvestSourceDirectory)" SuppressRootDirectory="true" Visible="false">
        <DirectoryRefId>TARGET_OF_HARVEST</DirectoryRefId>
        <PreprocessorVariable>var.SourceDirectoryOfMyData</PreprocessorVariable>
        <ComponentGroupName>ComponentGroup2Harvest</ComponentGroupName>
        <!-- 新增以下行,为所有生成的Component添加SharedDllRefCount属性 -->
        <ComponentProperties>SharedDllRefCount="yes"</ComponentProperties>
    </HarvestDirectory>
</ItemGroup>

该配置在WiX 3.11版本原生支持,修改后重新编译合并模块,所有harvest生成的组件都会自动携带SharedDllRefCount="yes"属性,符合你的需求。

方案2:通过XSLT转换处理Harvest输出(适用于复杂规则场景)

如果你需要针对部分组件设置属性(比如仅给dll/exe文件添加),可以自定义XSLT转换文件处理heat.exe的输出结果,配置方式如下:

  1. 编写自定义转换文件AddSharedDllRef.xslt,内容示例:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <!-- 匹配所有Component节点添加属性 -->
  <xsl:template match="wix:Component">
    <xsl:copy>
      <xsl:attribute name="SharedDllRefCount">yes</xsl:attribute>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
  1. 在HarvestDirectory节点中添加转换配置:
<Transforms>AddSharedDllRef.xslt</Transforms>

关于MSI合并阶段添加属性的说明

不支持在MSI合并合并模块的阶段修改合并模块内组件的属性,合并模块编译完成后内部的Component配置已经固化,合并到MSI的过程只是将组件元数据原样导入。如果需要修改属性,只能在合并模块的编译阶段完成,不推荐使用第三方工具直接修改MSI的Component表,容易引发兼容性问题。

内容的提问来源于stack exchange,提问作者labinger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 01:36:03