记录生成同时支持windows和linux的服务
作者:admin 来源: 2022/12/20 10:24:26

    在树莓派中运行net6服务程序

    在树莓派中安装net6运行环境并运行.net6应用程序

    记录生成同时支持windows和linux的服务

    net6独立部署到centos8(无需安装net6环境)

  .net6新增windows服务 

  .netCore2.1创建服务程序

    centos8中配置python服务程序

    ASP.NetCoreWeb以服务形式运行

    本文是在文章:3、“在树莓派中运行net6服务程序”,代码的基础上作改进。

    “在树莓派中运行net6服务程序”一文,已实现在树莓派中以服务的形式运行.net6程序,本文记录把该代码改进为同时支持在window下部署为windows 服务程序,

    一、在项目中添加nuget包:Microsoft.Extensions.Hosting.WindowsServices

    

    2、在program.cs内部,将UseWindowsService()添加到CreateHostBuilder

    

async static Task Main(string[] args)
        {
            IHost host = Host.CreateDefaultBuilder(args)
                .UseWindowsService()//用于windows服务
                .UseSystemd()//用于linux服务
                .ConfigureServices(services =>
                {
                    services.AddHostedService<Worker>();
                })
                .Build();
            await host.RunAsync();
        }
    3、发布


    

    4、打开命令行工具,使用以下命令安装和卸载该服务    


//安装服务
sc.exe create inoutWorkerService binPath=N:\myToolsProject\inout\net6\inout.Service\bin\Release\net6.0\publish\inout.Service.exe
//启动服务
sc.exe start inoutWorkerService
//停止服务
sc.exe stop inoutWorkerService
//删除服务
sc.exe delete inoutWorkerService


称      呼:
联系方式:
您的评论:
技术支持:l.w.dong@qq.com www.luweidong.cn
广州市   wx:lwdred
Copyright © 2014 三味书屋 All Rights Reserved
技术支持:l.w.dong@qq.com  sitemap xml  sitemap html

粤公网安备44010602011869号

粤ICP备13031080号-1