使用.NET Core框架创建WebJob的方式有些不同。您需要使用控制台应用程序(.NET Core)。
我强烈建议您遵循这个指南.NET Core中的Azure WebJobs
这是我的简单WebJob工作示例:(使用Core 2.2)
(程序)
public class Program
{
public static IConfigurationRoot config { get; private set; }
static void Main(string[] args)
{
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Console.WriteLine($"Current Environment : {(string.IsNullOrEmpty(environment) ? "Development" : environment)}");
config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
Console.WriteLine("URL API:" + config["appsettings node"]);
var builder = new HostBuilder()
.ConfigureWebJobs(webJobConfiguration =>
{
webJobConfiguration.AddTimers();
webJobConfiguration.AddAzureStorageCoreServices();
})
.ConfigureServices(serviceCollection => serviceCollection.AddSingleton<TimeneyeTasks>())
.Build();
builder.Run();
}
}
(我的类:) {{link1:}}
希望能对你有所帮助!