简体   繁体   English

如何使用.NET 2 System.Configuration.Install检测更新?

[英]How to detect an update using .NET 2 System.Configuration.Install?

I created a class derived from System.Configuration.Install for my installer. 我为我的安装程序创建了一个派生自System.Configuration.Install的类。
But the code in Uninstall() is being called when I try to update the application. 但是当我尝试更新应用程序时,正在调用Uninstall()中的代码。
How can I detect that the user is trying to update instead of uninstall? 如何检测用户是否尝试更新而不是卸载?

Maybe this post explains it better than me: 也许这篇文章比我解释得更好:

My problem boils down to: when the user performs an update (ie double clicks on MyAppVer2.msi when they already have MyAppVer1.msi installed) the Uninstall method inside my Installer is called first, but I have no apparent property to check from inside this method to detect that an update is being performed so that I can branch my code appropriately. 我的问题归结为:当用户执行更新时(即,当他们已经安装了MyAppVer1.msi时双击MyAppVer2.msi)首先调用我的安装程序中的Uninstall方法,但我没有明显的属性可以从内部检查检测正在执行更新的方法,以便我可以适当地分支我的代码。

您的安装项目中有一个设置默认情况下会“卸载”以前的版本,关闭此标志,那么您不必担心!

Blind guess here, but I'd start out by checking the Installer.Context property for a parameter . 盲目猜测,但我首先检查一下参数Installer.Context属性。 If that's no help, there may be something in the savedState parameter passed to Uninstall . 如果没有帮助,saveState参数中可能会有一些内容传递给Uninstall

Last chance would be to prompt the user , and set the child installers as appropiate. 最后一次机会是提示用户 ,并将子安装程序设置为适当的。

The deployment project that ships with Visual Studio is SEVERELY underpowered to deal with anything beyond the simpiliest scenarios. Visual Studio附带的部署项目严重不足以处理除最简单场景之外的任何事情。

In your case, you'll need to do one of the following: 在您的情况下,您需要执行以下操作之一:

  1. Figure out a way to set a flag prior to the original MSI being uninstalled, which you can check in the installer class. 找出一种在卸载原始MSI之前设置标志的方法,您可以在安装程序类中进行检查。
  2. Prompt the user visually in the installer class. 在安装程序类中以可视方式提示用户。
  3. Redesign your install/uninstall logic to not be dependant on the situation in which the uninstaller was called. 重新设计安装/卸载逻辑,使其不依赖于调用卸载程序的情况。

有没有理由你不能使用WIX,它可以更有效地处理这类事情,看看升级教程, 在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用.NET更新系统的日期和/或时间 - How to update the system's date and/or time using .NET 如何检测系统上是否存在.Net 3.5? - How to detect if .Net 3.5 is present on the System? 如何在计划任务中使用System.Configuration.Install.Installer? - How to use System.Configuration.Install.Installer with scheduled tasks? 如何使用 C# 代码检测系统上是否安装了“.Net Framework 4.6.1 Hotfix”? - How to detect whether “.Net Framework 4.6.1 Hotfix” is installed on System or not using C# Code? 如何检测系统时间是否已更改? (来自.net) - How do I detect if the system time is changed? (from .net) 如何打开格式化为.NET配置文件的文件以获取System.Configuration.Configuration对象 - How to open a file formatted as a .NET config file to get a System.Configuration.Configuration object 如何以编程方式更新log4net配置文件? - How can I programmatically update log4net configuration file? System.Configuration.Install.Installer实例如何获取目标文件夹? - How a System.Configuration.Install.Installer instance can get the destination folder? 从用户使用.NET(C#)登录系统时如何检测? - How to detect since when a user is logged into the system with .NET (C#)? Windows Update如何在GAC中安装.NET程序集? - How does Windows Update install .NET assemblies in the GAC?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM