.NET6 运行WindowsService

1、安装nuget包

Microsoft.Extensions.Hosting.WindowsServices

2、修改Program.cs

        public static void Main(string[] args)
        {
            var options = new WebApplicationOptions
            {
                Args = args,
                ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
            };
            var builder = WebApplication.CreateBuilder(options);
            builder.Host.UseWindowsService();
            builder.WebHost.UseUrls("http://*:8010");
            
            ....
            
        }

3、安装

sc create ...

 

posted @ 2022-07-30 13:39  b̶i̶n̶g̶.̶  阅读(512)  评论(1编辑  收藏  举报