.Net 4.7-Azure WebJob项目-NuGet更新后缺少JobHostConfiguration / RunAndBlock

问题描述

我有一个正在运行的项目,其中包含用于WebJob和存储的非常陈旧的NuGet软件包。大规模升级后,我仅在此块中遇到三个错误:

#Input
n = int(input('Enter n: '))
#Prime = 0
p = []
#Loopidty
for i in range(n):
  #Ask user to input x
  x = int(input('Enter a Number: '))

#Check if prime
  if x < 2:
    print('The number is not prime.')
  else:
      for n in range(2,x - 1):
          if x % n == 0:
              print('The number is not prime.')
              break
else:
          print('The number is prime.')
          p.append(x)
#Answer
Answer = sum(p) / n
print('The answer is: ',Answer)

错误:

    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();
    }

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

解决方法

如果要使用Azure WebJob SDK V3,则已删除JobHostConfigurationJobHost。在版本V3中,主机是IHost的实现。有关更多详细信息,请参阅herehere。此外,请注意,在版本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();
    }
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...