Azure Functions 项目中的 "Startup Code" 在哪里?

Where is the "Startup Code" in an Azure Fuctions project?

我正在尝试编写一个使用 ServiceBus 绑定作为触发器的 Azure 函数。我已将所有内容升级到 netstandard 2.0 和 WebJobs 包的预发布 v3.0 版本,因此我可以正确构建并生成元数据等所有内容。

当我尝试 运行 项目时,Azure Functions 主机启动但抱怨我没有定义函数,并建议我可能必须在启动代码中手动配置自定义绑定。我还收到与我尝试部署的函数相关的空引用错误,我怀疑这也可能是由未知的触发器绑定属性引起的。

我知道服务总线绑定不再内置,需要注册,但我不知道我应该在哪里做这件事。我的项目只是一个 class 库,它没有 "startup code".

这是我启动项目时得到的:

[1/5/2018 4:15:46 PM] A function whitelist has been specified, excluding all but the following functions: [ProcessCheckRecognition, ImageConversion]
[1/5/2018 4:15:47 PM] Generating 0 job function(s)
[1/5/2018 4:15:47 PM] Starting Host (HostId=9f4ea53c5136457d883d685e57164f08, Version=2.0.11353.0, ProcessId=12424, Debug=False, Attempt=0, FunctionsExtensionVersion=)
Listening on http://localhost:7071/
Hit CTRL-C to exit...
[1/5/2018 4:15:47 PM] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
[1/5/2018 4:15:47 PM] Job host started
[1/5/2018 4:15:47 PM] The following 1 functions are in error:
[1/5/2018 4:15:47 PM] ProcessCheckRecognition: Object reference not set to an instance of an object.

这是我的函数 class:

public static class JobResponse
{
    [FunctionName("ProcessJobResponse")]
    public static void Run([ServiceBusTrigger("ktl-jobresponse")]ResponseMessage message, TraceWriter log)
    {
    }
}

以及构建时生成的 function.json:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.7",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "serviceBusTrigger",
      "queueName": "ktl-jobresponse",
      "name": "message"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/KutuluWare.Functions.dll",
  "entryPoint": "KutuluWare.Functions.JobResponse.Run"
}

我应该在某个地方调用 config.UseServiceBus() 吗?如果是,该代码应该存放在哪里?

运行 func 命令并确保您使用的是 v2 工具(目前处于测试阶段):

您可以通过 运行 npm install -g azure-functions-core-tools@core

安装这些

另见 类似问题。