在dnxcore50上为控制台应用程序创建自定义托管服务

编程入门 行业动态 更新时间:2024-10-21 19:28:30
本文介绍了在dnxcore50上为控制台应用程序创建自定义托管服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个控制台应用程序,可以按计划的时间发送电子邮件.我正在创建Windows服务来执行此操作.但是Windows服务在core中不可用.我可以知道解决方案吗?

I have created a console app to send email on scheduled time. I am creating a windows service to do this. But windowsservices are not available in core. Can I know the solution for this.

在继承ServiceBase时出现错误,因为dnxcore50中没有System.ServiceProcess.我无法使用net451或其他框架,因为我的应用程序在生产中使用Core,因此我只使用了此dnxcore50.

I am getting an error while inheriting ServiceBase, as there is no System.ServiceProcess in dnxcore50. I can't user net451 or other framework as my application uses Core in production so I have use only this dnxcore50.

下面是我主要方法中的代码

Below is the code in my main method

var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(contentRootPath) .Build(); if(Debugger.IsAttached || args.Contains(-debug"))) { host.Run(); } 其他 { host.RunAsCustomService(); }

var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(contentRootPath) .Build(); if (Debugger.IsAttached || args.Contains("--debug")) { host.Run(); } else { host.RunAsCustomService(); }

}

下面是我的project.json文件

Below is my project.json file

{ 版本":"1.0.0- *", "dependencies":{ "Microsoft.AspNetCore.Http.Abstractions":"1.0.0&", "NETStandard.Library":"1.6.0&", "Newtonsoft.Json":"9.0.1", "Microsoft.Extensions.DependencyInjection":"1.0.0&", "Microsoft.Extensions.Logging.Console":"1.0.0&", "Microsoft.Extensions.Logging.Debug":"1.0.0&", "Microsoft.Extensions.PlatformAbstractions":"1.0.0&", "Bz.Business.Manager":"1.0.0- *", "Bz.Business.Models":"1.0.0- *", "Bz.Core.Repository":"1.0.0- *", "Serilog":"2.1.0&", "Serilog.Extensions.Logging":"1.1.0&", "Serilog.Sinks.File":"2.1.0&", "Serilog.Sinks.Literate":"2.1.0-dev-00031", "Serilog.Sinks.RollingFile":"2.1.0&", "Microsoft.Extensions.Configuration":"1.0.0&", "Microsoft.Extensions.Configuration.FileExtensions":"1.0.0&", "Microsoft.Extensions.Configuration.Json":"1.0.0&", "Microsoft.Extensions.Configuration.EnvironmentVariables":"1.0.0&", "Microsoft.AspNetCore.Hosting":"1.0.0&", "Microsoft.AspNetCore.Server.Kestrel":"1.0.0&", "Microsoft.AspNetCore.Hosting.Abstractions":"1.0.0&", "Microsoft.Framework.Runtime.Interfaces":"1.0.0-beta4" }, 框架":{ "netstandard1.6":{ 进口":"dnxcore50" } } }

{ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNetCore.Http.Abstractions": "1.0.0", "NETStandard.Library": "1.6.0", "Newtonsoft.Json": "9.0.1", "Microsoft.Extensions.DependencyInjection": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.PlatformAbstractions": "1.0.0", "Bz.Business.Manager": "1.0.0-*", "Bz.Business.Models": "1.0.0-*", "Bz.Core.Repository": "1.0.0-*", "Serilog": "2.1.0", "Serilog.Extensions.Logging": "1.1.0", "Serilog.Sinks.File": "2.1.0", "Serilog.Sinks.Literate": "2.1.0-dev-00031", "Serilog.Sinks.RollingFile": "2.1.0", "Microsoft.Extensions.Configuration": "1.0.0", "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.AspNetCore.Hosting": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.AspNetCore.Hosting.Abstractions": "1.0.0", "Microsoft.Framework.Runtime.Interfaces": "1.0.0-beta4" }, "frameworks": { "netstandard1.6": { "imports": "dnxcore50" } } }

下面是CustomWebHostService.cs

Below is the CustomWebHostService.cs

下面是错误

推荐答案

嗨 Ramya gollapudi ,

Hi Ramya gollapudi,

谢谢您在这里发布.

根据您的代码.我认为您的问题与ASP.NET论坛有关.

According to your code. I think your issue is related to ASP.NET forum.

您能告诉我们您的项目类型是什么吗?这是一个ASP.NET Web服务?如果是,我建议您重新发布

Could you tell us what type of your project? it is a ASP.NET webservices? if yes, I would suggest you repost

此处.

根据我的搜索.我找到了 类似的解决方案.

Based on my search. I find a similar solution.

您在这里有两个选择-使用Microsoft的WebHostService类,继承WebHostService或编写您自己的.

You've got a couple of options here - use Microsoft's WebHostService class, inherit WebHostService or write your own.

我希望这些信息对您有所帮助.

I hope the information is helpful to you.

最好的问候,

Hart

更多推荐

在dnxcore50上为控制台应用程序创建自定义托管服务

本文发布于:2023-11-16 18:17:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606666.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   控制台   应用程序   上为   托管服务

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!