您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

注册 Azure Functions 绑定扩展Register Azure Functions binding extensions

在 Azure Functions 版本 2.x 中,绑定以独立于函数运行时的包的形式提供。In Azure Functions version 2.x, bindings are available as separate packages from the functions runtime. 虽然 .NET 函数通过 NuGet 包访问绑定,但扩展捆绑包允许其他函数通过配置设置访问所有绑定。While .NET functions access bindings through NuGet packages, extension bundles allow other functions access to all bindings through a configuration setting.

请考虑以下与绑定扩展相关的项:Consider the following items related to binding extensions:

下表指明了何时以及如何注册绑定。The following table indicates when and how you register bindings.

开发环境Development environment 注册Registration
Functions 1.x 中注册in Functions 1.x
注册Registration
Functions 2.x 中注册in Functions 2.x
Azure 门户Azure portal 自动Automatic 自动Automatic
非 .NET 语言或本地 Azure Core Tools 开发Non-.NET languages or local Azure Core Tools development 自动Automatic 使用 Azure Functions Core Tools 和扩展捆绑包Use Azure Functions Core Tools and extension bundles
使用 Visual Studio 2019 的 C# 类库C# class library using Visual Studio 2019 使用 NuGet 工具Use NuGet tools 使用 NuGet 工具Use NuGet tools
使用 Visual Studio Code 的 C# 类库C# class library using Visual Studio Code 不适用N/A 使用 .NET Core CLIUse .NET Core CLI

使用 Azure Functions Core Tools 和扩展捆绑包进行本地开发Local development with Azure Functions Core Tools and extension bundles

扩展捆绑包进行发布的 Azure Functions 团队可通过中的设置的所有绑定host.json文件。Extension bundles make all bindings published by the Azure Functions team available through a setting in the host.json file. 进行本地开发,请确保具有最新版本Azure Functions Core ToolsFor local development, ensure you have the latest version of Azure Functions Core Tools.

若要使用扩展捆绑包,更新host.json文件以包括以下条目extensionBundle:To use extension bundles, update the host.json file to include the following entry for extensionBundle:

{
    "version": "2.0",
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
    }
}
  • id属性引用的命名空间的 Microsoft Azure Functions 扩展捆绑包。The id property references the namespace for Microsoft Azure Functions extension bundles.
  • version引用的包的版本。The version references the version of the bundle.

作为捆绑包更改中的包捆绑在版本增量。Bundle versions increment as packages in the bundle changes. 主版本的更改会发生仅移动时在绑定中的包的主版本。Major version changes happen only when packages in the bundle move a major version. version属性使用间隔表示法,用于指定版本范围The version property uses the interval notation for specifying version ranges. Functions 运行时总是选择接口定义的版本范围或间隔的最高允许版本。The Functions runtime always picks the maximum permissible version defined by the version range or interval.

后在项目中引用的扩展捆绑包,然后所有默认绑定都可供你的函数。Once you reference the extension bundles in your project, then all default bindings are available to your functions. 中提供的绑定扩展包是:The bindings available in the extension bundle are:

packagePackage VersionVersion
Microsoft.Azure.WebJobs.Extensions.CosmosDBMicrosoft.Azure.WebJobs.Extensions.CosmosDB 3.0.33.0.3
Microsoft.Azure.WebJobs.Extensions.DurableTaskMicrosoft.Azure.WebJobs.Extensions.DurableTask 1.8.01.8.0
Microsoft.Azure.WebJobs.Extensions.EventGridMicrosoft.Azure.WebJobs.Extensions.EventGrid 2.0.02.0.0
Microsoft.Azure.WebJobs.Extensions.EventHubsMicrosoft.Azure.WebJobs.Extensions.EventHubs 3.0.33.0.3
Microsoft.Azure.WebJobs.Extensions.SendGridMicrosoft.Azure.WebJobs.Extensions.SendGrid 3.0.03.0.0
Microsoft.Azure.WebJobs.Extensions.ServiceBusMicrosoft.Azure.WebJobs.Extensions.ServiceBus 3.0.33.0.3
Microsoft.Azure.WebJobs.Extensions.SignalRServiceMicrosoft.Azure.WebJobs.Extensions.SignalRService 1.0.01.0.0
Microsoft.Azure.WebJobs.Extensions.StorageMicrosoft.Azure.WebJobs.Extensions.Storage 3.0.43.0.4
Microsoft.Azure.WebJobs.Extensions.TwilioMicrosoft.Azure.WebJobs.Extensions.Twilio 3.0.03.0.0

使用 Visual Studio 2019 的 C# 类库C# class library with Visual Studio 2019

在 Visual Studio 2019 中,可使用 Install-Package 命令从包管理器控制台安装包,如以下示例所示:In Visual Studio 2019, you can install packages from the Package Manager Console using the Install-Package command, as shown in the following example:

Install-Package Microsoft.Azure.WebJobs.Extensions.ServiceBus -Version <TARGET_VERSION>

用于给定绑定的包的名称在该绑定的参考文章中提供。The name of the package used for a given binding is provided in the reference article for that binding. 有关示例,请参阅服务总线绑定参考文章的“包”部分For an example, see the Packages section of the Service Bus binding reference article.

将示例中的 <TARGET_VERSION> 替换为特定包版本,例如 3.0.0-beta5Replace <TARGET_VERSION> in the example with a specific version of the package, such as 3.0.0-beta5. NuGet.org 上的单个包页上列出了有效版本。与 Functions 运行时 1.x 或 2.x 对应的主版本在绑定的参考文章中指定。Valid versions are listed on the individual package pages at NuGet.org. The major versions that correspond to Functions runtime 1.x or 2.x are specified in the reference article for the binding.

使用 Visual Studio Code 的 C# 类库C# class library with Visual Studio Code

在“Visual Studio Code” 中,可在 .NET Core CLI 中,通过命令提示符使用 dotnet add package 命令来安装包,如以下示例所示:In Visual Studio Code, you can install packages from the command prompt using the dotnet add package command in the .NET Core CLI, as shown in the following example:

dotnet add package Microsoft.Azure.WebJobs.Extensions.ServiceBus --version <TARGET_VERSION>

.NET Core CLI 只能用于 Azure Functions 2.x 开发。The .NET Core CLI can only be used for Azure Functions 2.x development.

用于给定绑定的包的名称在该绑定的参考文章中提供。The name of the package to use for a given binding is provided in the reference article for that binding. 有关示例,请参阅服务总线绑定参考文章的“包”部分For an example, see the Packages section of the Service Bus binding reference article.

将示例中的 <TARGET_VERSION> 替换为特定包版本,例如 3.0.0-beta5Replace <TARGET_VERSION> in the example with a specific version of the package, such as 3.0.0-beta5. NuGet.org 上的单个包页上列出了有效版本。与 Functions 运行时 1.x 或 2.x 对应的主版本在绑定的参考文章中指定。Valid versions are listed on the individual package pages at NuGet.org. The major versions that correspond to Functions runtime 1.x or 2.x are specified in the reference article for the binding.

后续步骤Next steps