dotnetapi部署window服务

 参考:https://blog.csdn.net/liwan09/article/details/81740090

https://www.c-sharpcorner.com/article/how-to-host-asp-net-core-3-1-web-applications-as-windows-service/

nuget安装

Microsoft.AspNetCore.Hosting.WindowsServices

 

public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().RunAsService();
        }
 
        public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
            var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
            var pathToContentRoot = Path.GetDirectoryName(pathToExe);
 
            return WebHost.CreateDefaultBuilder(args)
                .UseContentRoot(pathToContentRoot)
                .UseStartup<Startup>();
        }

 

 

sc create StorageApi1 binPath= "F:\WeiCloudAPP\WeiCloudApp-2020\WeiCloudStorageAPI\bin\Release\netcoreapp2.2\publish\WeiCloudStorageAPI.exe --urls=http://*:5010"

 

posted @ 2020-11-26 16:39  wjl910  阅读(158)  评论(0)    收藏  举报