在Program.cs中为ASP.Net Core中的Quartz服务添加触发器时出错
错误-严重性代码描述项目文件行抑制状态错误CS1061“IWebHostBuilder”不包含“Services”的定义,找不到接受类型“IWebHostBuilder”的第一个参数的可访问扩展方法“Services”(是否缺少using指令或程序集引用?)
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
//webBuilder.UseStartup<Startup>();
webBuilder.Services.AddQuartz(q =>
{
q.UseMicrosoftDependencyInjectionScopedJobFactory();
// Just use the name of your job that you created in the Jobs folder.
var jobKey = new JobKey("TestTask");
q.AddJob<Orange38_Application.Scheduled_Tasks.TestTask>(opts => opts.WithIdentity(jobKey));
q.AddTrigger(opts => opts
.ForJob(jobKey)
.WithIdentity("TestTask-trigger")
//This Cron interval can be described as "run every minute" (when second is zero)
.WithCronSchedule("0 0/1 0 ? * * *")
);
});
webBuilder.Services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
});
1条答案
按热度按时间exdqitrt1#
请确保您使用的是.csproj文件中的
<Project Sdk="Microsoft.NET.Sdk.Web">
。然后您可以添加如下服务。或者在.net6之后,您应该使用
webapplication
构建器进行webhost参考:https://andrewlock.net/exploring-dotnet-6-part-2-comparing-webapplicationbuilder-to-the-generic-host/