netcore webapi 服务(win-service)部署
一、托管服务
- 安装依赖
PM> NuGet\Install-Package Microsoft.Extensions.Hosting.WindowsServices -Version 9.0.0 - 启动端口
{ "urls":"http://*:5100" } - 服务托管
var builder = WebApplication.CreateBuilder(args); // win service if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) builder.Host.UseWindowsService(); var app = builder.Build(); - 启动脚本
start.bat@echo off :: 发布路径 set path="E:\Apricot\bin\Release\net8.0\publish" :: 启动文件 set app="Apricot.exe" :: 创建服务 %SystemRoot%\system32\sc.exe create Apricot.Service binPath="%path%/%app%" start=auto displayname="Apricot.Service" :: 设置描述 %SystemRoot%\system32\sc.exe description Apricot.Service "Apricot.Service 托管服务。" :: 启动服务 echo Apricot.Service starting... %SystemRoot%\system32\net.exe start Apricot.Service echo Apricot.Service started. pause - 停止脚本
stop.bat@echo off echo ============Apricot.Service Stoping ============ %SystemRoot%\system32\net.exe stop Apricot.Service echo ============Apricot.Service Stoped============ echo ============Apricot.Service Deleting============ %SystemRoot%\system32\sc.exe delete Apricot.Service echo ============Apricot.Service Deteted Start============ pause
二、nssm 服务安装
如有帮助,欢迎转载,转载请注明原文链接:https://www.cnblogs.com/study10000/p/17191814.html








浙公网安备 33010602011771号