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