windows WiX,虽然我们忘记设置 Permanent="yes",但如何防止文件卸载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2812788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WiX, how to prevent files from uninstalling though we forgot to set Permanent="yes"
提问by Doc Brown
We have a product installer created with Wix, containing a program package ("V1") and some configuration files. Now, we are going to make a major upgrade with a new product code, where the old version of the product is uninstalled and "V2" is installed. What we want is to save one of the configuration files from uninstalling, since it is needed for the V2, too. Unfortunately, we forgot to set the Permanent="yes"
option when we delivered V1 (read this questionfor more information).
我们有一个用 Wix 创建的产品安装程序,其中包含一个程序包(“ V1”)和一些配置文件。现在,我们将使用新的产品代码进行重大升级,卸载旧版本的产品并安装“ V2”。我们想要的是从卸载中保存配置文件之一,因为 V2 也需要它。不幸的是,我们Permanent="yes"
在交付 V1 时忘记设置选项(阅读此问题了解更多信息)。
Here comes the question: is there an easy way of preventing the uninstall of the fileanyhow? Of course, we could add a custom action to the script to backup the file before uninstallation, and another custom action to restore it afterwards, but IMHO that seems to be overkill for this task, and might interfere with other parts of the MSI registration process.
问题来了:有没有一种简单的方法可以防止文件卸载?当然,我们可以在脚本中添加一个自定义操作来在卸载前备份文件,然后添加另一个自定义操作来恢复它,但恕我直言,这对于此任务似乎有点过分,并且可能会干扰 MSI 注册过程的其他部分.
EDIT: And yes, the NeverOverwrite="yes"
attribute is already set in V2, and the behaviour is as I described it.
编辑:是的,该NeverOverwrite="yes"
属性已在 V2 中设置,行为与我描述的一样。
I don't think it will help to change something directly in the component parameters of V2. Perhaps there's a chance to modify the registry somehow in a custom action before uninstalling V1 so the installer service thinks the configuration file in V1 was installed with Permanent="yes"
?
我认为直接在 V2 的组件参数中更改某些内容无济于事。也许有机会在卸载 V1 之前以某种方式在自定义操作中修改注册表,以便安装程序服务认为 V1 中的配置文件是使用Permanent="yes"
?
采纳答案by Charles Gargent
Try the NeverOverwrite
attribute for the configuration file
尝试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.
如果此属性设置为“是”,并且组件的键路径文件或键路径注册表项已存在,则安装程序不会安装或重新安装组件。
EDIT
编辑
I have just tested this in a test setup. At first it didn't work because I had scheduled the RemoveExistingProducts
action before InstallInitialize
sequence. This removes the old product before the new product is installed so it can't compare.
我刚刚在测试设置中对此进行了测试。起初它不起作用,因为我RemoveExistingProducts
在InstallInitialize
序列之前安排了动作。这会在安装新产品之前删除旧产品,因此无法进行比较。
However when I set it to after InstallFinalize
it did work, it left the file there even though the original setup didn't have NeverOverwrite
set. here are my two test examples
但是,当我将它设置为在InstallFinalize
它起作用后,即使原始设置没有设置,它也会将文件留在那里NeverOverwrite
。这是我的两个测试示例
version 1.0.0.0
版本 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>
version 1.0.1.0
版本 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>
回答by Pascal Ganaye
The way I am fixing this is very simple. I don't install yourapp.config files but only yourapp.config.new On the first run the application before doing anything else check for the config file. If there is none make a copy yourapp.config.new to yourapp.config
我解决这个问题的方法非常简单。我不安装 yourapp.config 文件,而只安装 yourapp.config.new 在第一次运行应用程序之前,先检查配置文件。如果没有复制 yourapp.config.new 到 yourapp.config
This is very simple it doesn't use any special attributes. When the application is uninstalled the config file is not uninstalled. When the application is re-installed file is disturbed. Note that when the application is repaired the config is not modified either.
这很简单,它不使用任何特殊属性。卸载应用程序时,不会卸载配置文件。当应用程序被重新安装文件受到干扰。请注意,修复应用程序时,配置也不会被修改。