windows – WiX,如何防止文件卸载虽然我们忘了设置Permanent =“yes”

前端之家收集整理的这篇文章主要介绍了windows – WiX,如何防止文件卸载虽然我们忘了设置Permanent =“yes”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们有一个使用Wix创建的产品安装程序,其中包含程序包(“V1”)和一些配置文件.现在,我们将使用新的产品代码进行重大升级,其中卸载了旧版本的产品并安装了“V2”.我们想要的是保存其中一个配置文件免于卸载,因为它也需要V2.不幸的是,当我们发送V1( read this question获取更多信息)时,我们忘记设置Permanent =“yes”选项.

这里有一个问题:是否有一种简单的方法可以防止文件的卸载?当然,我们可以在脚本中添加一个自定义操作来在卸载之前备份文件,然后再添加另一个自定义操作来恢复它,但恕我直言,这个任务似乎有点过分,并且可能会干扰MSI注册过程的其他部分.

编辑:是的,NeverOverwrite =“yes”属性已经在V2中设置,行为就像我描述的那样.

我不认为在V2的组件参数中直接更改某些内容会有所帮助.也许有机会在卸载V1之前以某种方式在自定义操作中修改注册表,以便安装程序服务认为V1中的配置文件是使用Permanent =“yes”安装的?

尝试配置文件的NeverOverwrite属性

If this attribute is set to ‘yes’,the
installer does not install or
reinstall the component if a key path
file or a key path registry entry for
the component already exists.

编辑

我刚刚在测试设置中对此进行了测试.起初它没有用,因为我在InstallInitialize序列之前安排了RemoveExistingProducts操作.这会在安装新产品之前删除旧产品,因此无法进行比较.

但是,当我将它设置为InstallFinalize后,它确实有效,即使原始设置没有设置NeverOverwrite,它也会将文件保留在那里.这是我的两个测试示例

版本1.0.0.0

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="35d07bf8-a729-402d-83d6-fdc55799a3d5" Language="1033" Manufacturer="..." Name="test1" UpgradeCode="9773a278-068d-4fac-8241-4a5b7e54f15a" Version="1.0.0.0">
        <Package Compressed="no" InstallerVersion="200" />
        <Property Id="ALLUSERS" Value="1" />
        <Upgrade Id="9773a278-068d-4fac-8241-4a5b7e54f15a">
            <UpgradeVersion OnlyDetect="no" Property="REMOVEOLDVERSION" Maximum="1.0.0.0" IncludeMaximum="no" />
            <UpgradeVersion OnlyDetect="yes" Property="NEWERFOUND" Minimum="1.0.0.0" IncludeMinimum="no" />
        </Upgrade>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder" Name="ProgramFilesFolder">
                <Directory Id="INSTALLDIR" Name="test1">
                    <Component Id="New_Text_Document.txt" Guid="{CCA38D83-A890-4528-B11D-DA2E2DCDED93}" Feature="ProductFeature">
                        <File Id="New_Text_Document.txt" KeyPath="yes" Source="Harvest\ProgramFilesFolder\INSTALLDIR\New Text Document.txt" />
                    </Component>
                </Directory>
            </Directory>
        </Directory>
        <Feature Id="ProductFeature" Level="1" Title="CompletePackage" Description="The complete Product." Display="expand" />
        <CustomAction Id="NewerFound" Error="A later version of [ProductName] is already installed" />
        <InstallExecuteSequence>
            <Custom Action="NewerFound" After="FindRelatedProducts">NEWERFOUND</Custom>
            <RemoveExistingProducts After="InstallFinalize" />
        </InstallExecuteSequence>
        <UIRef Id="WixUI_Minimal" />
        <Media Id="1" />
        <UI />
    </Product>
</Wix>

版本1.0.1.0

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="1da36626-d760-4c4c-8a5c-3eb3841dbfd5" Language="1033" Manufacturer="..." Name="test1" UpgradeCode="9773a278-068d-4fac-8241-4a5b7e54f15a" Version="1.0.1.0">
        <Package Compressed="no" InstallerVersion="200" />
        <Property Id="ALLUSERS" Value="1" />
        <Upgrade Id="9773a278-068d-4fac-8241-4a5b7e54f15a">
            <UpgradeVersion OnlyDetect="no" Property="REMOVEOLDVERSION" Maximum="1.0.1.0" IncludeMaximum="no" />
            <UpgradeVersion OnlyDetect="yes" Property="NEWERFOUND" Minimum="1.0.1.0" IncludeMinimum="no" />
        </Upgrade>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder" Name="ProgramFilesFolder">
                <Directory Id="INSTALLDIR" Name="test1">
                    <Component Id="New_Text_Document.txt" Guid="{CCA38D83-A890-4528-B11D-DA2E2DCDED93}" Feature="ProductFeature" NeverOverwrite="yes">
                        <File Id="New_Text_Document.txt" KeyPath="yes" Source="Harvest\ProgramFilesFolder\INSTALLDIR\New Text Document.txt" />
                    </Component>
                </Directory>
            </Directory>
        </Directory>
        <Feature Id="ProductFeature" Level="1" Title="CompletePackage" Description="The complete Product." Display="expand" />
        <CustomAction Id="NewerFound" Error="A later version of [ProductName] is already installed" />
        <InstallExecuteSequence>
            <Custom Action="NewerFound" After="FindRelatedProducts">
NEWERFOUND</Custom>
            <RemoveExistingProducts After="InstallFinalize" />
        </InstallExecuteSequence>
        <UIRef Id="WixUI_Minimal" />
        <Media Id="1" />
        <UI />
    </Product>
</Wix>

猜你在找的Windows相关文章