我目前有一个运行 ASP.NET Core 3.1 的相当大的控制台应用程序。我现在的任务是在我们的一台服务器上将这项工作作为窗口服务进行。我已经准备好让它在服务器本身上作为服务运行,但是,我目前遇到的一件事是如何在代码中实际更改它以使其作为服务运行而不会破坏它。
我已经发现一对夫妇像教程这是做解释如何运行一个控制台应用程序作为一种服务,但是,所有的人,我已经从一个全新的项目中找到的开始。我的问题是我当前的项目已经写好了。我寻求帮助的主要问题是如何让我的项目作为 Windows 服务工作,同时保持当前在 startup.cs 中的功能。对于上下文,这是我当前的 startup.cs 和 program.cs:
启动文件
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSignalR();
services.AddTransient<SharePointUploader>();
services.AddTransient<FileUploadService>();
services.AddSingleton<UploaderHub>();
//services.AddAuthentication(IISDefaults.AuthenticationScheme);
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
services.AddAuthorization();
}
// This method gets called by the runtime. Use this method to configure the HTTP …Run Code Online (Sandbox Code Playgroud)