【发布时间】:2015-06-27 00:25:29
【问题描述】:
根据我找到的here,我能够构建一个安装和部署项目,该项目可以正确安装我正在使用的服务。 不幸的是,当我更新应用程序(并且可能是它附带的服务)时,关于如何卸载服务的信息绝对为零。
如何将卸载程序添加到服务项目安装程序?
在 ProjectInstaller 类中,我添加了以下代码:
[System.Security.Permissions.SecurityPermission( System.Security.Permissions.SecurityAction.Demand )]
public override void Uninstall( IDictionary savedState ) {
base.Uninstall( savedState );
try { this.TRSInstaller.Uninstall( savedState ); } catch { }
}
我不得不这样做,因为在没有 try/catch 的情况下尝试它会导致服务被正确删除,但是抛出了一个异常,不允许我删除整个程序,所以我无法安装新版本。
但是,这不会删除服务。
这是 VS 吐出的 ProjectInstaller 类的代码:
namespace TriviaRetriever {
partial class ProjectInstaller {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose( bool disposing ) {
if ( disposing && ( components != null ) ) {
components.Dispose( );
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent( ) {
this.TRProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
this.TRSInstaller = new System.ServiceProcess.ServiceInstaller();
//
// TRProcessInstaller
//
this.TRProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.TRProcessInstaller.Password = null;
this.TRProcessInstaller.Username = null;
//
// TRSInstaller
//
this.TRSInstaller.Description = "Service for automatically downloading your trivia.";
this.TRSInstaller.DisplayName = "Trivia Retriever";
this.TRSInstaller.ServiceName = "TriviaRetriever";
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.TRProcessInstaller,
this.TRSInstaller});
}
#endregion
private System.ServiceProcess.ServiceProcessInstaller TRProcessInstaller;
private System.ServiceProcess.ServiceInstaller TRSInstaller;
}
}
namespace TriviaRetriever {
[RunInstaller( true )]
public partial class ProjectInstaller : System.Configuration.Install.Installer {
public ProjectInstaller( ) {
InitializeComponent( );
}
[System.Security.Permissions.SecurityPermission( System.Security.Permissions.SecurityAction.Demand )]
public override void Uninstall( IDictionary savedState ) {
base.Uninstall( savedState );
try { this.TRSInstaller.Uninstall( savedState ); } catch { }
}
}
}
我需要怎么做才能在我卸载应用程序时成功删除 Windows 服务? (它们紧紧地捆绑在一起;如果一个不存在,另一个也不应该存在)。
【问题讨论】:
标签: c# visual-studio-2013 windows-services custom-action setup-deployment