VS 2008 安装包不能自动卸载上一个版本的解决办法

来源:互联网 发布:flickerplate.min.js 编辑:程序博客网 时间:2024/05/11 03:29

<!-- /* Font Definitions */ @font-face{font-family:SimSun;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:宋体;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"Cambria Math";panose-1:2 4 5 3 5 4 6 3 2 4;mso-font-charset:1;mso-generic-font-family:roman;mso-font-format:other;mso-font-pitch:variable;mso-font-signature:0 0 0 0 0 0;}@font-face{font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:-1610611985 1073750139 0 0 159 0;}@font-face{font-family:"/@SimSun";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-unhide:no;mso-style-qformat:yes;mso-style-parent:"";margin-top:0cm;margin-right:0cm;margin-bottom:10.0pt;margin-left:0cm;line-height:115%;mso-pagination:widow-orphan;font-size:11.0pt;font-family:"Calibri","sans-serif";mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:SimSun;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:"Times New Roman";mso-bidi-theme-font:minor-bidi;}a:link, span.MsoHyperlink{mso-style-priority:99;color:blue;mso-themecolor:hyperlink;text-decoration:underline;text-underline:single;}a:visited, span.MsoHyperlinkFollowed{mso-style-noshow:yes;mso-style-priority:99;color:purple;mso-themecolor:followedhyperlink;text-decoration:underline;text-underline:single;}.MsoChpDefault{mso-style-type:export-only;mso-default-props:yes;mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:SimSun;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:"Times New Roman";mso-bidi-theme-font:minor-bidi;}.MsoPapDefault{mso-style-type:export-only;margin-bottom:10.0pt;line-height:115%;}@page Section1{size:595.3pt 841.9pt;margin:72.0pt 72.0pt 72.0pt 72.0pt;mso-header-margin:35.4pt;mso-footer-margin:35.4pt;mso-paper-source:0;}div.Section1{page:Section1;}-->

VS 2008 安装包不能自动卸载上一个版本的解决办法

VS2008中制作了一个安装包,主程序是一个 Windows Service,安装完毕后自动运行,希望能在安装新版本的时候自动卸载老版本。

在添加的 Setup Project中设置如下:

DetectNewerInstalledVersion = TRUE

RemovePreviousVersions = TRUE

Version 必须大于等于 1.0.0

查找了多方资料,发现从 VS2008开始,删除上一版本的操作并不会先调用旧版本的卸载操作,而是直接重新安装新版本,并试图利用文件覆盖规则来处理旧文件(http://msdn.microsoft.com/en-us/library/aa370552%28v=VS.85%29.aspx

 

Here's an excerpt from theRemovePreviousVesrions property's documentation:

If you have set both install anduninstall custom actions in an application's setup project, and you haveenabled the RemovePreviousVersions property in Visual Studio 2005, the previousversion of the product is uninstalled during an upgrade. However, this behaviorchanged in Visual Studio 2008 as follows:

In Visual Studio 2005, the customactions were called as follows on an upgrade from v1.0.0 to v1.0.1:

v1.0.0 custom action Uninstall()

v1.0.1 custom action Install()

In Visual Studio 2008, the uninstallaction is not called, as follows:

v1.0.1 custom action Install()

If you created custom actionsrelying on the old behavior, you need to modify your code for the new behavior.This behavior change affects only updates, not uninstalls.

 

创建一个服务及其安装工程的,可以参考如下帖子: http://programmingcorner.blogspot.com/2009/02/creating-and-installing-windows-service.html

安装上述的帖子完成的安装,并不能完全解决问题,因为当你安装新版本的时候,上一个版本的服务还在并且可能还在运行,所以直接安装新版本会失败,解决方法是在安装包完成后,执行一个脚本,该脚本会改变默认的2008升级规则,而改成2005的: http://stackoverflow.com/questions/617409/script-to-change-action-sequence-records-in-an-msi/

 

该方法我验证过,可以写在上一版本然后安装新版本

 

我也试过在安装服务先检查服务是否存在,然后先删除,后安装,但是遭遇 The specified service hasbeen marked for deletion. 服务虽然被删除成功,但在接着安装的时候遭遇次错误,一般是因为该服务还被其他对象reference着。

其它有用的帖子:

How to deal with "Error 1001. The specified servicealready exists" when install a service using installer package?
http://i1.social.microsoft.com/Forums/resources/images/trans.gif?cver=363%0d%0a

http://social.msdn.microsoft.com/forums/en-US/winformssetup/thread/b2d1bd22-8499-454e-9cec-1e42c03e2557/

Custom action condition to run for a new or upgradedproduct.

http://geekswithblogs.net/mnf/archive/2006/08/14/87894.aspx

2008 中的文件覆盖规则:

http://msdn.microsoft.com/en-us/library/aa370552%28v=VS.85%29.aspx

利用代码添加删除 Windows 服务

http://www.c-sharpcorner.com/UploadFile/sachin.nigam/InstallingWinServiceProgrammatically11262005061332AM/InstallingWinServiceProgrammatically.aspx

How do I eliminate “The specified service already exists”when I install new versions of my software?

http://stackoverflow.com/questions/451573/how-do-i-eliminate-the-specified-service-already-exists-when-i-install-new-versio/617385

http://stackoverflow.com/questions/451573/how-do-i-eliminate-the-specified-service-already-exists-when-i-install-new-versio/617385