Dot-Net
在不解除安裝的情況下升級 Windows 服務
目前我必須在安裝新版本之前解除安裝舊版本的服務。我很確定這與它不夠聰明,無法在添加新服務條目之前更新或刪除舊服務條目有關。
如果服務已經存在,有沒有辦法讓安裝程序跳過註冊服務?(我可以假設安裝文件夾和服務名稱在版本之間不會改變。)
另外,有沒有辦法在解除安裝時自動停止服務?
編輯:
我正在使用 MSI 包和 Visual Studio 安裝項目。
我已經使用 WiX 完成了此操作,它使用 ServiceInstall 和服務控制命令生成 .MSI 文件:
<Component Id='c_WSService' Guid='*'> <File Id='f_WSService' Name='WSService.exe' Vital='yes' Source='..\wssvr\release\wsservice.exe' KeyPath="yes" /> <ServiceInstall Id='WSService.exe' Name='WSService' DisplayName='[product name]' Type='ownProcess' Interactive='no' Start='auto' Vital='yes' ErrorControl='normal' Description='Provides local and remote access to [product name] search facilities.' /> <ServiceControl Id='WSService.exe' Name='WSService' Start='install' Stop='both' Remove='uninstall' Wait='yes' /> </Component>這將停止服務,安裝新版本並重新啟動服務。