.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 ...

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章