註冊 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
Non-.NET 語言或本機 Azure Core 工具開發Non-.NET languages or local Azure Core Tools development 自動Automatic 使用 Azure Functions Core Tools 和延伸模組配套Use Azure Functions Core Tools and extension bundles
C#使用 Visual Studio 的類別庫C# class library using Visual Studio 使用 NuGet 工具Use NuGet tools 使用 NuGet 工具Use NuGet tools
使用 Visual Studio Code 的 C# 類別庫C# class library using Visual Studio Code N/AN/A 使用 .NET Core CLIUse .NET Core CLI

本機開發的延伸模組配套Extension bundles for local development

延伸模組配套是2.x 版執行時間的本機開發技術,可讓您將一組相容的函式系結延伸模組,新增至您的函式應用程式專案。Extension bundles is a local development technology for the version 2.x runtime that lets you add a compatible set of Functions binding extensions to your function app project. 當您部署至 Azure 時,這些擴充套件會包含在部署套件中。These extension packages are then included in the deployment package when you deploy to Azure. 配套會讓 Microsoft 發佈的所有系結都可透過主機 json檔案中的設定來取得。Bundles makes all bindings published by Microsoft available through a setting in the host.json file. 組合中定義的延伸模組套件彼此相容,這可協助您避免封裝之間的衝突。Extension packages defined in a bundle are compatible with each other, which helps you avoid conflicts between packages. 在本機開發時,請確定您使用的是最新版本的Azure Functions Core ToolsWhen developing locally, make sure you are using the latest version of Azure Functions Core Tools.

使用 Azure Functions Core Tools 或 Visual Studio Code,將延伸模組配套用於所有本機開發。Use extension bundles for all local development using Azure Functions Core Tools or Visual Studio Code.

如果您未使用延伸模組配套,則必須先在本機電腦上安裝 .NET Core 2.x SDK,再安裝任何系結延伸模組。If you don't use extension bundles, you must install the .NET Core 2.x SDK on your local computer before you install any binding extensions. 配套會移除本機開發的這項需求。Bundles removes this requirement for local development.

若要使用延伸模組配套,請更新主機的 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)"
    }
}

下列屬性可用於extensionBundleThe following properties are available in extensionBundle:

屬性Property 描述Description
id Microsoft Azure 函式擴充功能配套的命名空間。The namespace for Microsoft Azure Functions extension bundles.
version 要安裝的配套版本。The version of the bundle to install. 函數執行時間一律會挑選版本範圍或間隔所定義的最大允許版本。The Functions runtime always picks the maximum permissible version defined by the version range or interval. 上述版本值允許所有來自1.0.0 的套件組合版本,但不包括2.0.0。The version value above allows all bundle versions from 1.0.0 up to but not including 2.0.0. 如需詳細資訊,請參閱指定版本範圍的間隔標記法For more information, see the interval notation for specifying version ranges.

配套版本隨著套件在配套中的增加而變更。Bundle versions increment as packages in the bundle change. 主要版本變更會在配套中的套件以主要版本遞增時進行,這通常會與函式執行時間的主要版本變更一致。Major version changes occur when packages in the bundle increment by a major version, which usually coincides with a change in the major version of the Functions runtime.

預設配套所安裝的目前延伸模組集合會在此副檔名 json檔案中列舉。The current set of extensions installed by the default bundle are enumerated in this extensions.json file.

具有# Visual Studio 的 C 類別庫C# class library with Visual Studio

Visual Studio中,您可以使用 [安裝套件] 命令從套件管理員主控台安裝套件,如下列範例所示:In Visual Studio, 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.

請以特定版本的套件 (例如 3.0.0-beta5) 取代範例中的 <TARGET_VERSION>Replace <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.

如果您使用Install-Package來參考系結,則不需要使用延伸模組配套。If you use Install-Package to reference a binding, you do not need to use extension bundles. 這個方法是 Visual Studio 內建的類別庫所特有。This approach is specific for class libraries built in Visual Studio.

C#具有 Visual Studio Code 的類別庫C# class library with Visual Studio Code

注意

我們建議使用延伸模組配套,讓函式自動安裝一組相容的系結延伸模組套件。We recommend using extension bundles to have Functions automatically install a compatible set of binding extension packages.

Visual Studio Code中,使用 .NET Core CLI 中C#的dotnet add package命令,從命令提示字元安裝類別庫專案的套件。In Visual Studio Code, install packages for a C# class library project from the command prompt using the dotnet add package command in the .NET Core CLI. 下列範例示範如何新增系結:The following example demonstrates how you add a binding:

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

.NET Core CLI 只能用於 Azure Functions 2.x 開發。The .NET Core CLI can only be used for Azure Functions 2.x development.

<BINDING_TYPE_NAME>所需系結的參考文章中所提供的封裝名稱取代。Replace <BINDING_TYPE_NAME> with the name of the package provided in the reference article for your desired binding. 您可以在支援的系結清單中找到所需的系結參考文章。You can find the desired binding reference article in the list of supported bindings.

請以特定版本的套件 (例如 3.0.0-beta5) 取代範例中的 <TARGET_VERSION>Replace <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