区分卸载/安装和升级应用程序
因此,我有这个应用程序,我们正在为其制作进一步的开发版本。
如果应用程序被用户卸载(比如说从“添加/删除程序”),那么我希望应用程序删除文件系统中包含应用程序相关信息的某个文件夹。
但是,如果应用程序升级(通过下载该应用程序的较新安装程序并安装它),那么我希望它保留该文件夹。
我的印象(目前)不可能区分卸载/安装和仅将应用程序从一个版本更新到另一个版本,因为 .NET 部署项目将升级视为另一个卸载/安装过程,但这应该以某种方式是可能的。
感谢您抽出时间以及我可能得到的任何答案。
So, I have this application for which we are producing further development versions.
If the application gets uninstalled by the user (from Add/Remove Programs let's say), then I want the application to delete a certain folder in the file system which contains app-related information.
However, if the application is upgraded (by downloading a newer installer for this app and installing it), then I want it to keep that folder.
I am under the impression (at the moment) that it is not possible to differentiate between uninstalling/installing and just updating an application from one version to another, because the .NET deployment projects treat upgrading as just another uninstall/install procedure, but this should be possible somehow.
Thanks for taking the time and whatever answers I may get.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
安装程序具有三个 GUID 代码:ProductCode、PackageCode 和 UpgradeCode,您可以使用它们来管理这些场景: UpgradeCode 就像应用程序 ID,不应在版本之间更改; PackageCode 标识您的安装版本,ProductCode 标识您的软件版本。
您可以通过增加 ProductVersion 值来更改 ProductCode。
Windows 使用 ProductCode 来查看该应用程序是否已安装在系统上。如果您使用具有相同 ProductCode 和 PackageCode 的安装程序重新安装,您将获得修复/卸载选项。
The installer has three GUID codes, ProductCode, PackageCode and UpgradeCode that you can use to manage these scenarios: The UpgradeCode is like an application id and shouldn't change between versions; the PackageCode identifies a release of your setup and the ProductCode identifies a release of your software.
You can change the ProductCode by incrementing the ProductVersion value.
Windows uses the ProductCode to see if the application is already installed on a system. If you reinstall using an installer with the same ProductCode and PackageCode you get a Repair/Uninstall option.
这不是直接答案,但您是否考虑过使用第三方安装软件?我们使用 InnoSetup 来分发 .Net 应用程序,我们发现它相当易于使用且非常灵活。它当然可以处理您所描述的内容。
This is not a direct answer, but have you considered using third-party installation software? We use InnoSetup for distributing a .Net application, and we find it fairly easy to use and very flexible. It could certainly handle what you are describing.
您是否尝试过使用 ClickOnce 部署?它处理应用程序的所有安装和升级。通过更改更新中包含的文件的发布状态,您可以控制文件是否被更新覆盖或保持不变。卸载应用程序后,所有文件都将被删除。
Have you tried using the ClickOnce deployment? It handles all the install and upgrading of the application. By changing the publish status of the files included in the update you can control if the file gets overwritten with an update or stays the same. When the application is uninstalled all the files will be removed.
使用 wix 安装程序将使您能够进行这种区分。这是一种更实际的方法,但它会起作用。
Using a wix installer will allow you to make this differentiation. This is a more hands on approach, but it will work.
您还可以尝试添加一些自定义预安装操作,将提到的文件夹复制到某个临时文件夹,然后安装后操作将其复制回原来的位置。但请首先考虑上述建议,例如使用更强大的安装程序,或 clickOnce。
You could also try adding some custom preinstall action, which copies the mentioned folder to some temporary folder and then a post install action copies it back to its place. But please, first consider the above sugestions, such as using a more powerfull installer, or clickOnce.
我最终还找到了一种方法来检查应用程序是否正在升级或者是否是全新安装:
卸载应用程序时,该信息将被删除。
该值将包含您计算机上当前安装的版本。如果此安装的版本小于您尝试安装的应用程序的版本,则您将遵循升级的逻辑路径
如果您在注册表中找不到该键下的任何内容,则意味着这是一个全新的版本安装(计算机上安装此应用程序之前没有其他应用程序)。在这里,您遵循刚刚安装的另一条逻辑路径
希望这对某人有帮助。
I've eventually also figured out a way to check if the application is upgrading or if it is a fresh install:
When the application is uninstalled that information is removed.
This value will contain the version that is currently installed on your computer. If this installed version is smaller than the version of the application you are trying to install, then you follow the logic path of UPGRADING
If you can't find anything in the registry under that key, that means that this is a fresh install (there is no other application before this one installed on the computer). And here you follow the other logic path of just installing
Hope this helps somebody.