WiX:在卸载或升级时保持Heat收获的文件

时间:2014-03-15 00:47:43

标签: xslt wix

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

感谢您的任何建议!

3 个答案:

答案 0 :(得分:3)

如果将以下内容保存到名为“例如”的文件中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>

Permanent - 属性,根据WiX帮助文件,执行以下操作: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以小写字母添加全部内容&#39; myapp.exe.config&#39;。这样您就不必处理大小写问题。另请注意,我假设您使用-suid - 选项来加热,即不是为每个组件创建具有随机字母/数字的ID,每个组件通常将其文件名称为Id。

答案 1 :(得分:1)

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

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

答案 2 :(得分:0)

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