.Net 4.7 - Azure WebJob 项目 - JobHostConfiguration/RunAndBlock 在 NuGet 更新后丢失

.Net 4.7 - Azure WebJob Project - JobHostConfiguration/RunAndBlock missing after NuGet updates

我有一个工作项目,其中为 WebJob 和存储设置了非常过时的 NuGet 包。大规模升级后,我只在这个块中遇到三个错误:

    private static void Main()
    {
        var config = new JobHostConfiguration();

        config.Queues.MaxDequeueCount    = Convert.ToInt32(ConfigurationManager.AppSettings["MaxDequeueCount"]);
        config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["MaxPollingInterval"]));
        config.Queues.BatchSize          = Convert.ToInt32(ConfigurationManager.AppSettings["BatchSize"]); ;
        config.NameResolver              = new QueueNameResolver();

        if (config.IsDevelopment)
        {
            config.UseDevelopmentSettings();
        }

        var host = new JobHost();
        host.RunAndBlock();
    }

错误:

Error CS0246: The type or namespace name 'JobHostConfiguration' could not be found (are you missing a using directive or an assembly reference?) \Program.cs:11
Error CS7036: There is no argument given that corresponds to the required formal parameter 'options' of 'JobHost.JobHost(IOptions<JobHostOptions>, IJobHostContextFactory)' \Program.cs:23
Error CS1061: 'JobHost' does not contain a definition for 'RunAndBlock' and no accessible extension method 'RunAndBlock' accepting a first argument of type 'JobHost' could be found (are you missing a using directive or an assembly reference?) \Program.cs:24

所有帮助和问题都显示了.Net Core 代码。我在 .Net Framework 4.7.2 上。我该如何在旧框架中设置此代码?

如果您想要 Azure WebJob SDK V3,JobHostConfigurationJobHost 已被删除。在版本 V3 中,主机是 IHost 的实现。更多详情请参考here and here。此外,请注意,在版本 3 中,您需要显式安装 WebJobs SDK 所需的存储绑定扩展。

例如(版本 3 中的队列触发器)

#Install package Microsoft.Azure.WebJobs.Extensions.Storage 3.x
static async Task Main()
{
    var builder = new HostBuilder();
    builder.ConfigureWebJobs(b =>
    {
        b.AddAzureStorageCoreServices();
        b.AddAzureStorage(a => {
            a.BatchSize = 8;
            a.NewBatchThreshold = 4;
            a.MaxDequeueCount = 4;
            a.MaxPollingInterval = TimeSpan.FromSeconds(15);
        });
    });
    var host = builder.Build();
    using (host)
    {
        await host.RunAsync();
    }
}