註冊 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

延伸模組配套是一種部署技術,可讓您將一組相容的函式系結擴充功能新增至函式應用程式。Extension bundles is a deployment technology that lets you add a compatible set of Functions binding extensions to your function app. 當您建立應用程式時,會新增一組預先定義的延伸模組。A predefined set of extensions are added when you build your app. 組合中定義的延伸模組套件彼此相容,這可協助您避免封裝之間的衝突。Extension packages defined in a bundle are compatible with each other, which helps you avoid conflicts between packages. 您會在應用程式的 host. json 檔案中啟用延伸模組配套。You enable extension bundles in the app's host.json file.

您可以使用版本2.x 和更新版本的函式執行時間的延伸模組組合。You can use extension bundles with version 2.x and later versions of the Functions runtime. 在本機開發時,請確定您使用的是最新版本的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 local development using Azure Functions Core Tools, Visual Studio Code, and when you build remotely.

如果您未使用延伸模組配套,則必須先在本機電腦上安裝 .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. 延伸模組配套會移除本機開發的這項需求。Extension 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)"
    }
}

extensionBundle提供下列屬性:The following properties are available in extensionBundle:

屬性Property 描述Description
idid 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. 套件組合中的主要版本變更通常會與函式執行時間的主要版本變更一致。Major version changes in the bundle usually coincide with a change in the major version of the Functions runtime.

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

C# 具有 Visual Studio 的類別庫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.

請以特定版本的套件 (例如 <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的個別套件頁面上。對應至函式執行時間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 don't 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 that contains the binding you need. 您可以在支援的系結清單中找到所需的系結參考文章。You can find the desired binding reference article in the list of supported bindings.

請以特定版本的套件 (例如 <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的個別套件頁面上。對應至函式執行時間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