【问题标题】:WiX: Keep File Harvested by Heat on uninstall or upgradeWiX:在卸载或升级时保持文件被 Heat 收集
【发布时间】:2014-03-19 06:07:28
【问题描述】:

我正在使用热量从 .csproj 文件中获取二进制文件。这很好用,但是,当我卸载或升级应用程序时,我想将收获的文件“MyApp”.exe.config 留在安装目录中,这样用户就不会丢失他们的默认设置。我是否需要与 heat 命令一起应用专门的 XSLT 转换?或者由于收获的结果只是片段中的几个组件,也许最好手动添加文件以便我可以单独控制每个文件?我是 WiX 新手,很难找到答案。

感谢您的任何建议!

【问题讨论】:

  • 您能否详细说明“用户s ... 默认设置”?您是否使用 .NET 2.0 及更高版本的 application settings 类?您是在说“应用程序”设置、“用户”设置还是两者兼而有之?您是使用 Visual Studio C# 或 VB.NET 设置设计器生成它们吗?如您所知,如果为单个用户更改用户设置,则当前值不会存储在“MyApp”.exe.config 中。
  • 嗨,汤姆,感谢您的回复。这是一个 .Net 2.0 C# 应用程序,它使用设置设计器,并且 .exe.config 文件中的所有设置都是 userSettings。看来我误解了 .exe.config 文件的作用。 msdn 链接有助于清除它。它说“设置架构将在应用程序第一次为该用户保存设置时按需创建 user.config 文件。”看来我不需要担心“MyApp”.exe.config 被覆盖或卸载。这是正确的吗?

标签: xslt wix


【解决方案1】:

如果您将以下内容保存到名为 e.g. transform.xslt 并将-t transform.xslt 添加到命令行以进行加热,加热结果应进行转换并将Permanent-属性添加到MyApp.exe.config

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
    xmlns="http://schemas.microsoft.com/wix/2006/wi"
    exclude-result-prefixes="wix">

    <xsl:template match="wix:Wix">
      <xsl:copy>
        <xsl:apply-templates select="@*" />
        <xsl:apply-templates />
      </xsl:copy>
    </xsl:template>

    <xsl:template match="wix:Component">

        <!-- Just copy the tag itself -->
        <xsl:copy>
            <!-- Copy all attributes -->
            <xsl:apply-templates select="@*" />

            <!-- Here comes the distinction: if you find our special component, do some special things -->
            <xsl:choose>
                <!-- Note that the string is translated to all lower case, so you don't have to care about being case sensitive or not -->
                <xsl:when test="translate(@Id,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = 'myapp.exe.config'">
                    <!-- Here we will add the Permanent-attribute to this very special component -->
                    <xsl:attribute name="Permanent">yes</xsl:attribute>
                </xsl:when>
            </xsl:choose>

            <!-- Now take the rest of the inner tag -->
            <xsl:apply-templates select="node()" />
        </xsl:copy>

    </xsl:template>

    <xsl:template match="@*|node()">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()" />
      </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

根据 WiX 帮助文件,Permanent-属性执行以下操作:If this attribute is set to 'yes', the installer does not remove the component during an uninstall. The installer registers an extra system client for the component in the Windows Installer registry settings (which basically just means that at least one product is always referencing this component). Note that this option differs from the behavior of not setting a guid because although the component is permanent, it is still patchable (because Windows Installer still tracks it), it's just not uninstallable.

请注意,我已经为文件名添加了小写转换,因此不要检查MyApp.exe.config,而是添加全部小写“myapp.exe.config”。这样您就不必处理小写/大写问题。另请注意,我假设您使用 -suid-option 进行加热,即不是为每个组件创建带有随机字母/数字的 Id,而是每个组件通常将其文件名作为 Id。

【讨论】:

  • 谢谢塔菲特!似乎我误解了“MyApp”.exe.config 的角色,所以看起来我可能不需要阻止它被覆盖或卸载。您可以在我对上面汤姆评论的回复中阅读更多内容。但是,我确实很欣赏上面的 xslt 文件,因为随着我变得更高级,我可能需要知道如何执行此操作。我不知道怎么写那个文件。
【解决方案2】:

如果您进行重大升级并在最后使用 RemoveExistingProducts,则升级遵循文件覆盖规则,其中包括不替换用户修改的文件。

卸载时它仍然会被删除,但如果产品被卸载,为什么有人需要卸载应用程序的配置文件?

【讨论】:

    【解决方案3】:

    看来我误解了 .exe.config 文件的作用。这个msdn link 帮助澄清了一点。它说“设置架构将在应用程序第一次为该用户保存设置时按需创建 user.config 文件。”看来我不需要担心“MyApp”.exe.config 被覆盖或卸载。感谢汤姆为我指明了正确的方向!

    【讨论】:

      猜你喜欢
      • 2011-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      • 2011-03-18
      • 1970-01-01
      • 2011-02-15
      相关资源
      最近更新 更多