【问题标题】:Handling dependencies when installing windows service with ServiceInstaller/ServiceProcessInstaller使用 ServiceInstaller/ServiceProcessInstaller 安装 windows 服务时处理依赖关系
【发布时间】:2013-05-23 07:42:59
【问题描述】:

我正在尝试构建一个可自行安装的 Windows 服务。我有一个这样定义的安装程序类:

[RunInstaller(true)]
public class MyServiceInstaller : Installer
{
    public MyServiceInstaller()
    {
        var serviceProcessInstaller = new ServiceProcessInstaller
            {
                Account = ServiceAccount.LocalSystem
            };

        var serviceInstaller = new ServiceInstaller
            {
                DisplayName = "MyService",
                StartType = ServiceStartMode.Automatic,
                ServiceName = "MyService",
                Description = "My Service Description"
            };

        Installers.Add(serviceProcessInstaller);
        Installers.Add(serviceInstaller);
    }
}

这是我用来执行安装的代码:

public void Install()
{
    using (var assemblyInstaller = new AssemblyInstaller(
      typeof(MyService).Assembly, 
      null) { 
        UseNewContext = true 
      })
    {
        var state = new Hashtable();
        try
        {
            assemblyInstaller.Install(state);
            assemblyInstaller.Commit(state);
        }
        catch
        {
            try
            {
                assemblyInstaller.Rollback(state);
            }
            catch {}

            throw;
        }
    }
}

当我从我的 ASP.NET 应用程序触发安装时,包含我的 Windows 服务的程序集安装在某处:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\xxxxxxx\25c14c59\a945a1e6\assembly\dl3\abf52138\74461ad8_8d5bce01\MyService.EXE

问题是,这个程序集是唯一安装的文件。

问题:

  1. 如何还包括我的程序集所依赖的程序集?
  2. 如何同时包含我的 app.config 文件?

【问题讨论】:

    标签: .net deployment windows-services dependencies installation


    【解决方案1】:

    完全不使用安装程序解决了这个问题。相反,我使用 WMI (Win32_Service) 来注册我的服务,然后它就从原始位置运行。这是 codeproject 的相关article

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-11
      • 2010-11-06
      • 2018-11-28
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 2015-07-15
      相关资源
      最近更新 更多