.Net Core快速创建Windows服务

1.新建.Net Core控制台程序,添加新建项Windows服务:

修改Progran.cs:

class Program
    {
        static void Main(string[] args)
        {
            ServiceBase[] services = new ServiceBase[] { new WinService() };
            ServiceBase.Run(services);
        }
    }

 发布设置部署模式为 独立:

发布后文件里会有一个exe文件:

我们需要使用命令来将其创建为Windows服务:

sc create MyWinService binpath="***.exe"

扫描二维码关注公众号,回复: 5140202 查看本文章

停止服务:

sc stop MyService

卸载服务:

sc delete MyService

猜你喜欢

转载自www.cnblogs.com/weiBlog/p/10346501.html