如何使用安装程序包安装用.Net编写的Windows服务?

问题描述 投票:1回答:1

我彻底遵循了Microsoft Tutorial: Create a Windows service app。特别是,我看到了this code

static void Main(string[] args)
{
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[]
    {
        new MyNewService(args)
    };
    ServiceBase.Run(ServicesToRun);
}

使用相应的ProjectInstaller,也在本教程中进行了描述,我能够使用installutil以本教程中描述的方式成功安装该服务。

现在,以上代码建议我可以使用该程序安装一系列服务。例如,我建立了一些服务,并提出了以下类型的代码:

static void Main(string[] args)
{
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[]
    {
        new Service1(args),
        new Service2(args),
        new Service3(args),
        new Service4(args)
    };
    ServiceBase.Run(ServicesToRun);
}

再次,用相应的ProjectInstaller,用installutil安装这4个服务很好。我安装了服务,甚至可以运行它们。

但是,我找不到将其打包到安装程序包中的方法。 Microsoft documentation提到ClickOnce,WiX和InstallShield软件包安装程序。在我的开发团队中,我们使用Advanced Installer。这些安装程序包似乎都没有在其文档中显示如何使用上述4服务Main程序安装服务。每次,我都会看到如何一次安装一项服务。例如,我可以为我的每项服务编写上述Main程序之一,然后将这些程序打包在安装程序包中。

有可能吗?怎么样?我真的不想为每个服务创建一个Visual Studio项目,只是为了安装它们。如果上述服务无法实现,那我有什么可能性?

c# .net windows-services installer installutil
1个回答
0
投票

您可以尝试使用包含所有要安装的服务的安装项目。但是您需要安装Microsoft Visual Studio Installer项目插件(框图标)这是可以帮助您的指南:https://www.c-sharpcorner.com/UploadFile/b7531b/create-simple-window-service-and-setup-project-with-installa/也许当您在安装项目上添加自定义操作时,您可以添加更多服务以包含在安装文件中。

© www.soinside.com 2019 - 2024. All rights reserved.