区分卸载/安装和升级应用程序

发布于 2024-09-29 07:00:45 字数 280 浏览 0 评论 0原文

因此,我有这个应用程序,我们正在为其制作进一步的开发版本。

如果应用程序被用户卸载(比如说从“添加/删除程序”),那么我希望应用程序删除文件系统中包含应用程序相关信息的某个文件夹。

但是,如果应用程序升级(通过下载该应用程序的较新安装程序并安装它),那么我希望它保留该文件夹。

我的印象(目前)不可能区分卸载/安装和仅将应用程序从一个版本更新到另一个版本,因为 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

左岸枫 2024-10-06 07:00:45

安装程序具有三个 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.

贵在坚持 2024-10-06 07:00:45

这不是直接答案,但您是否考虑过使用第三方安装软件?我们使用 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.

乞讨 2024-10-06 07:00:45

您是否尝试过使用 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.

浪漫人生路 2024-10-06 07:00:45

使用 wix 安装程序将使您能够进行这种区分。这是一种更实际的方法,但它会起作用。

Using a wix installer will allow you to make this differentiation. This is a more hands on approach, but it will work.

萌辣 2024-10-06 07:00:45

您还可以尝试添加一些自定义预安装操作,将提到的文件夹复制到某个临时文件夹,然后安装后操作将其复制回原来的位置。但请首先考虑上述建议,例如使用更强大的安装程序,或 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.

蓝天白云 2024-10-06 07:00:45

我最终还找到了一种方法来检查应用程序是否正在升级或者是否是全新安装:

  • 应用程序在注册表中留下一些有关其自身的信息(应用程序名称、版本号等)。这通常存储在

LocalMachine\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{应用程序的 GUID}

卸载应用程序时,该信息将被删除。

  • 但是,您可以在安装应用程序版本时检查该信息(这可以通过在部署项目中添加一些自定义操作来完成)。我在 BeforeInstall 方法下检查它,并在注册表中查找 DisplayVersion 值,如下所示:


RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{AppGUIDHere}");
string version = (string)regKey.GetValue("DisplayVersion");

  • 该值将包含您计算机上当前安装的版本。如果此安装的版本小于您尝试安装的应用程序的版本,则您将遵循升级的逻辑路径

  • 如果您在注册表中找不到该键下的任何内容,则意味着这是一个全新的版本安装(计算机上安装此应用程序之前没有其他应用程序)。在这里,您遵循刚刚安装的另一条逻辑路径

希望这对某人有帮助。

I've eventually also figured out a way to check if the application is upgrading or if it is a fresh install:

  • The application leaves some information about itself in the registry (application name, version number etc.). This is usually stored within

LocalMachine\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{Application's GUID}

When the application is uninstalled that information is removed.

  • But you can check for that information when you are installing a version of your application (this can be done by adding some custom actions in the deployment project). I check it under the BeforeInstall method and look in the registry for the DisplayVersion value, like so:


RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{AppGUIDHere}");
string version = (string)regKey.GetValue("DisplayVersion");

  • 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文