註冊 Azure Functions 繫結延伸模組Register Azure Functions binding extensions

在 Azure Functions 第 2.x 中,繫結可用以從 functions 執行階段的個別封裝。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
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 所發行的所有繫結host.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.

若要使用延伸模組套件組合,更新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)"
    }
}

下列屬性可用於extensionBundle:The 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. Functions 執行階段一律會挑選版本範圍或間隔所定義的最高允許版本。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. 套件組合中的增加主要版本,通常會伴隨 Functions 執行階段的主要版本中的變更時,就會發生主要版本變更。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.

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

C#使用 Visual Studio 類別庫C# class library with Visual Studio

Visual Studio,您可以從 Package Manager Console 來安裝封裝Install-package命令,如下列範例所示: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,安裝套件C#類別庫專案,從命令提示字元使用dotnet 新增套件.NET Core CLI 命令。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