在windows 服务中托管asp.net core

SDK 2.1.300

官方示例

1、添加运行标识符

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
</PropertyGroup>

2、添加包引用 dotnet add package Microsoft.AspNetCore.Hosting.WindowsServices -v 2.1.0 -s https://www.nuget.org/api/v3

dotnet命令

包源

3、确认导入是否成功

 <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="2.1.0" />
</ItemGroup>

4、修改Program Main 函数

 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)
.UseKestrel()
.UseUrls("http://*:5001", "http://*:5002")
.ConfigureAppConfiguration((context, config) =>
{
// Configure the app here.
})
.UseContentRoot(pathToContentRoot)
.UseStartup<Startup>();
}

5、发布运行

dotnet publish -c Release -o "F:\winservices\mvcApp21"

6、使用sc.exe工具创建服务 此处使用系统原始DOS命令

发布根目录下:sc create mvcApp21 binPath= "F:\winservices\mvcApp21\mvcApp21.exe"

确保 binPath= 参数与其值之间存在空格

启动服务 sc start MyService

查看服务状态 sc query MyService

停止服务 sc stop MyService

删除服务 sc delete MyService

7、可能遇到的问题

8、.net core 部署服务其他方案

使用NSSM把.Net Core部署至Windows 服务

9、回顾.net 部署服务

使用Topshelf创建Windows 服务

wcf服务

windows 服务中托管asp.net core的更多相关文章

  1. 在 Windows 服务中托管 ASP.NET Core

    众所周知,ASP.NET Core采用了和传统ASP.NET不同的托管和HTTP处理方式,即把服务器和托管环境完全解耦.ASP.NET Core内置了两个HTTP服务器实现,一个是基于libuv实现的 ...

  2. 在Windows服务中托管 ASP.NET Core的坑

    按照官网教程 https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/windows-service?view=aspnetcore- ...

  3. .NET 6学习笔记(3)——在Windows Service中托管ASP.NET Core并指定端口

    在上一篇<.NET 6学习笔记(2)--通过Worker Service创建Windows Service>中,我们讨论了.NET Core 3.1或更新版本如何创建Windows Ser ...

  4. [转帖]以Windows服务方式运行ASP.NET Core程序

    以Windows服务方式运行ASP.NET Core程序 原作者blog: https://www.cnblogs.com/guogangj/p/9198031.htmlaspnet的blog 需要持 ...

  5. .Net Core 项目在Windows服务中托管【转载】

    本文以创建的WebAPI项目为例子进行讲解(本人使用VS Code创建的项目) 1.使用VS Code创建WebAPI项目(项目名称自定义) 2.在创建的项目csproj项目文件中,确认是否存在运行时 ...

  6. 以Windows服务方式运行ASP.NET Core程序

    我们对ASP.NET Core的使用已经进行了相当一段时间了,大多数时候,我们的Web程序都是发布到Linux主机上的,当然了,偶尔也有需求要发布到Windows主机上,这样问题就来了,难道直接以控制 ...

  7. 如何优雅的利用Windows服务来部署ASP.NET Core程序

    上一篇文章中我给大家讲述了五种部署ASP.NET Core网站的方法,其中有一种方式是通过Windows服务来进行部署,这样既可以做到开启自启动,又不会因为iis的反向代理而损失部分性能.但是美中不足 ...

  8. 以Windows服务方式运行ASP.NET Core程序【转载】

    我们对ASP.NET Core的使用已经进行了相当一段时间了,大多数时候,我们的Web程序都是发布到Linux主机上的,当然了,偶尔也有需求要发布到Windows主机上,这样问题就来了,难道直接以控制 ...

  9. 如何托管ASP.NET Core应用到Windows Service中

    (此文章同时发表在本人微信公众号"dotNET开发经验谈",欢迎右边二维码来关注.) 题记:正在构思一个中间件的设计,考虑是否既可以使用最新的技术,也可以兼顾传统的部署模式.所以有 ...

随机推荐

  1. [Swift]LeetCode147. 对链表进行插入排序 | Insertion Sort List

    Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted l ...

  2. [Swift]LeetCode401. 二进制手表 | Binary Watch

    A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom ...

  3. [Swift]LeetCode479. 最大回文数乘积 | Largest Palindrome Product

    Find the largest palindrome made from the product of two n-digit numbers. Since the result could be ...

  4. MySql综合知识汇总

    本文实验的测试环境:Windows 10+cmd+MySQL5.6.36+InnoDB Mysql驱动:com.mysql.jdbc.Driver MysqlURL:jdbc:mysql://loca ...

  5. 自定义圆形的ProgressBar

    1.自定义圆形的ProgressBar 效果图: 圆形ProgressBar的样式主要有以下几个,我们这里以progressBarStyleLarge为例进行样式的修改,其他的类似. <Prog ...

  6. Python Bs4 回顾

    BeautifulSoup bs4主要使用find()方法和find_all()方法来搜索文档. find()用来搜索单一数据,find_all()用来搜索多个数据 find_all()与find() ...

  7. C#版 - PAT乙级(Basic Level)真题 之 1021.个位数统计 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - P ...

  8. Asp.Net SignalR - 简单聊天室实现

    简单聊天室 使用持久链接类我们就可以做一些即时通讯的应用了,我使用Group做了一个简单的聊天室,先上图技术细节下面再讲 可以加入聊天室.创建聊天室.发送消息,下面就说说我是如何通过Group做出来的 ...

  9. javascript基础修炼(11)——DOM-DIFF的实现

    目录 一. 再谈从Virtual-Dom生成真实DOM 二. DOM-Diff的目的 三. DOM-Diff的基本算法描述 四. DOM-Diff的简单实现 4.1 期望效果 4.2 DOM-Diff ...

  10. DAL分页

    using System;using System.Collections.Generic;using LModel.DTO;using Newtonsoft.Json;using System.Da ...