为什么未检测到我的 Azure WebJob 应用程序中的 TimerTrigger 函数?

Why is my TimerTrigger'd function in my Azure WebJob app not being detected?

我的 Azure WebJob 控制台应用无法识别我设置的 TimerTrigger

我有 Visual Studio 生成的默认值 Program.cs:

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

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

    var host = new JobHost();

    host.RunAndBlock();
  }
}

我将我的新功能添加到 Functions.cs:

public static void MyFunction([TimerTrigger("0 */2 * * * *",
                                            RunOnStartup = true)]
                              TimerInfo timerInfo,
                              TextWriter log)
{
  log.WriteLine("MyFunction started!");
}

(我安装了 WebJobs.Extensions NuGet 包,所以我的代码可以正常编译。)

我还添加了这一行:

config.UseTimers();

this answer中提到的Main功能,但由于某些原因,我的新功能仍然没有被触发。

当我启动应用程序时,我看到以下输出:

Found the following functions:
MyNamespace.Functions.ProcessQueueMessage
Job host started

所以它没有看到我的新函数。

为什么会发生这种情况,我该如何解决?

将我Program.cs的内容与网上其他人发布的内容(包括the TimerTrigger docs)进行比较后,我发现了一个小差异。

Main函数中,我改成:

var host = new JobHost();

至:

var host = new JobHost(config);

它奏效了。我确定我之前没有更改它,所以显然这是 Azure WebJob 模板中的错误。