windows 服务中托管asp.net core
在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
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、可能遇到的问题
- 使用 powershell创建服务会报错,参见其他博友文章。在Windows服务中托管 ASP.NET Core的坑
8、.net core 部署服务其他方案
9、回顾.net 部署服务
windows 服务中托管asp.net core的更多相关文章
- 在 Windows 服务中托管 ASP.NET Core
众所周知,ASP.NET Core采用了和传统ASP.NET不同的托管和HTTP处理方式,即把服务器和托管环境完全解耦.ASP.NET Core内置了两个HTTP服务器实现,一个是基于libuv实现的 ...
- 在Windows服务中托管 ASP.NET Core的坑
按照官网教程 https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/windows-service?view=aspnetcore- ...
- .NET 6学习笔记(3)——在Windows Service中托管ASP.NET Core并指定端口
在上一篇<.NET 6学习笔记(2)--通过Worker Service创建Windows Service>中,我们讨论了.NET Core 3.1或更新版本如何创建Windows Ser ...
- [转帖]以Windows服务方式运行ASP.NET Core程序
以Windows服务方式运行ASP.NET Core程序 原作者blog: https://www.cnblogs.com/guogangj/p/9198031.htmlaspnet的blog 需要持 ...
- .Net Core 项目在Windows服务中托管【转载】
本文以创建的WebAPI项目为例子进行讲解(本人使用VS Code创建的项目) 1.使用VS Code创建WebAPI项目(项目名称自定义) 2.在创建的项目csproj项目文件中,确认是否存在运行时 ...
- 以Windows服务方式运行ASP.NET Core程序
我们对ASP.NET Core的使用已经进行了相当一段时间了,大多数时候,我们的Web程序都是发布到Linux主机上的,当然了,偶尔也有需求要发布到Windows主机上,这样问题就来了,难道直接以控制 ...
- 如何优雅的利用Windows服务来部署ASP.NET Core程序
上一篇文章中我给大家讲述了五种部署ASP.NET Core网站的方法,其中有一种方式是通过Windows服务来进行部署,这样既可以做到开启自启动,又不会因为iis的反向代理而损失部分性能.但是美中不足 ...
- 以Windows服务方式运行ASP.NET Core程序【转载】
我们对ASP.NET Core的使用已经进行了相当一段时间了,大多数时候,我们的Web程序都是发布到Linux主机上的,当然了,偶尔也有需求要发布到Windows主机上,这样问题就来了,难道直接以控制 ...
- 如何托管ASP.NET Core应用到Windows Service中
(此文章同时发表在本人微信公众号"dotNET开发经验谈",欢迎右边二维码来关注.) 题记:正在构思一个中间件的设计,考虑是否既可以使用最新的技术,也可以兼顾传统的部署模式.所以有 ...
随机推荐
- [Swift]LeetCode273. 整数转换英文表示 | Integer to English Words
Convert a non-negative integer to its english words representation. Given input is guaranteed to be ...
- [Swift]LeetCode345. 反转字符串中的元音字母 | Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string. Example 1: In ...
- [Swift]LeetCode841. 钥匙和房间 | Keys and Rooms
There are N rooms and you start in room 0. Each room has a distinct number in 0, 1, 2, ..., N-1, an ...
- Firefox 多行标签的解决方案分享
更新了 Quantum 以后 TabMixPlus 就不能用了,我最中意的多行标签也没了,捣鼓了一下终于重新回来了. 指南: https://discourse.mozilla.org/t/tabs- ...
- Ubuntu12.04下安装NS3.25
实验室项目的需求,要使用到NS3做仿真,使用实验室的电脑,Ubuntu12.04,版本比较低,建议大家使用16.04,这样安装依赖文件时不会出现版本过低的问题 (没管最后也安装成功了).下面就安装步骤 ...
- ubuntu 16.04 更改默认Python版本
一般Ubuntu默认的Python版本都为2.x, 如何改变Python的默认版本呢?假设我们需要把Python3.5设置为默认版本: 首先查看Python默认版本: ubuntu@user~$:py ...
- IDEA激活码(2019)
如您激活出现问题,请点击这里加入:软件激活问题解决群 前言 IDEA已然成为我最热爱的一款编辑器,作为一个从Eclipse阵营转过来的coder,确实能感受到IDEA的强大,而我电脑桌面的Eclips ...
- WebSocket(2)---实现游戏公告功能
实现游戏公告功能 实现功能:游戏管理里发布游戏公告,其它游戏玩家页面能够马上接受到游戏公告信息. 下面直接上代码案例,这里主要展示关键代码,底部有源码. 一.案例 1.pom.xml文件 主要是添加s ...
- BitmapToASCii
using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using Syste ...
- 服务器Windows 2008R2 C盘清理
今天因为连服务器的时间慢了很多,然后看了一下C盘的空间,OMG剩下222K.然后一直上网找解决方案. 按照惯例,应该开一个360看看,C盘清理啊,搬家什么的.360告知的竟然是没有可以搬移的,所以,这 ...