可选地在升级时保留旧版本的组件 [英] Optionally leave old version of component on upgrade

查看:23
本文介绍了可选地在升级时保留旧版本的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试设置 WiX 组件,以便用户可以指定安装程序不应在 MajorUpgrade 上升级该组件.我有以下代码,但这意味着如果满足条件,则不会安装新版本,但也会删除旧版本.

I've been trying to set up a WiX component such that the user can specify that the installer should not upgrade that component on a MajorUpgrade. I had the following code, but this means that if the condition is met then the new version is not installed, but the old version is also removed.

<Component Id="ExampleComponent" GUID="{GUID here}">
  <Condition>NOT(KEEPOLDFILE="TRUE")</Condition>
  <File Id="ExampleFile" Name="File.txt" KeyPath="yes" Source="File.txt"/>
</Component>

理想情况下,如果用户指定KEEPOLDFILE=TRUE",则应保留File.txt"的现有版本.我已经研究过使用 Permanent 属性,但这看起来并不相关.

Ideally, if the user specifies "KEEPOLDFILE=TRUE", then the existing version of "File.txt" should be kept. I've looked into using the Permanent attribute, but this doesn't look relevant.

这是否可以在不使用 CustomActions 的情况下实现?

Is this possible to achieve without using CustomActions?

推荐答案

多一点背景信息会有用,但是:

A bit more background information would be useful, however:

  1. 如果您的主要升级提前排序(例如 afterInstallInitialize),则升级是卸载后重新安装,因此保存文件是一个棘手的提议,因为您会保存它,然后进行新安装,然后恢复它.

  1. If your major upgrade is sequenced early (e.g. afterInstallInitialize) the upgrade is an uninstall followed by a fresh install, so saving the file is a tricky proposition because you'd save it, then do the new install, then restore it.

如果升级较晚,则在升级过程中应用文件覆盖规则,因此无论如何都不会被替换.您需要做一些事情,例如使创建和修改时间戳相同,以便 Windows 用新的时间戳覆盖它.在这种情况下,解决方案是运行以​​保留旧文件"为条件的自定义操作,因此您可以执行相反的操作:

If the upgrade is late, then file overwrite rules apply during the upgrade, therefore it won't be replaced anyway. You'd need to do something such as make the creation and modify timestamps identical so that Windows will overwrite it with the new one. The solution in this case would be to run a custom action conditioned on "keep old file", so you'd do the reverse of this:

https://blogs.msdn.microsoft.com/astebner/2013/05/23/updating-the-last-modified-time-to-prevent-windows-installer-from-updating-an-unversioned-file/

而且也不清楚那个文件是否总是更新,所以如果实际上它没有更新,那为什么还要问客户是否保留它呢?

And it's also not clear if that file is ALWAYS updated, so if in fact it has not been updated then why bother to ask the client whether to keep it?

  1. 通过将其组件 ID 设置为 null 来忽略 Windows Installer 行为可能更简单,如下所述:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa368007(v=vs.85).aspx

然后你可以对文件做你想做的事情.如果您已经使用组件 guid 安装了它,那么此解决方案为时已晚.

Then you can do what you want with the file. If you've already installed it with a component guid it's too late for this solution.

  1. 有更好的解决方案,需要应用参与安装此文件的模板版本.该应用程序制作了它始终使用的副本.在升级时,模板文件总是被替换,当应用程序在升级后第一次运行时,它会询问是使用新文件(因此它复制并覆盖它正在使用的文件)还是继续使用现有文件.在我看来,将这些问题委托给安装通常不是最佳解决方案.

设置像永久这样的属性通常不是一个好主意,因为它们不是您可以随心所欲打开和关闭的项目属性 - 它们适用于系统上的组件 ID,而永久意味着永久.

Setting attributes like Permanent is typically not a good idea because they are not project attributes you can turn on and off on a whim - they apply to that component id on the system, and permanent means permanent.

这篇关于可选地在升级时保留旧版本的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆