撰寫 Azure Functions 並在本機進行測試Code and test Azure Functions locally

雖然您能夠在 Azure 入口網站中開發及測試 Azure Functions,但許多開發人員仍偏好本機開發體驗。While you're able to develop and test Azure Functions in the Azure portal, many developers prefer a local development experience. Functions 可讓您輕鬆使用最喜愛的程式碼編輯器及開發工具,在本機電腦上建立及測試函式。Functions makes it easy to use your favorite code editor and development tools to create and test functions on your local computer. 您的本機函式可以連線到即時 Azure 服務,而且您可以在本機電腦上使用完整的 Functions 執行階段進行偵錯。Your local functions can connect to live Azure services, and you can debug them on your local computer using the full Functions runtime.

本機開發環境Local development environments

您在本機電腦上開發函式的方式取決於您的語言和工具喜好設定。The way in which you develop functions on your local computer depends on your language and tooling preferences. 下表中的環境支援本機開發:The environments in the following table support local development:

環境Environment LanguagesLanguages 描述Description
Visual Studio CodeVisual Studio Code C#(類別程式庫) C#指令碼 (.csx)JavaScriptPowerShellPythonC# (class library), C# script (.csx), JavaScript, PowerShell, Python 適用於 VS Code 的 Azure Functions 擴充功能將 Functions 支援新增至 VS Code。The Azure Functions extension for VS Code adds Functions support to VS Code. 需要 Core Tools。Requires the Core Tools. 使用 2.x 版 Core Tools 時,支援在 Linux、MacOS 和 Windows 上進行開發。Supports development on Linux, MacOS, and Windows, when using version 2.x of the Core Tools. 若要深入了解,請參閱使用 Visual Studio Code 建立第一個函式To learn more, see Create your first function using Visual Studio Code.
命令提示字元或終端機Command prompt or terminal C#(類別程式庫) C#指令碼 (.csx)JavaScriptPowerShellPythonC# (class library), C# script (.csx), JavaScript, PowerShell, Python Azure Functions Core Tools提供核心執行階段與範本來建立啟用本機開發函式。Azure Functions Core Tools provides the core runtime and templates for creating functions, which enable local development. 2.x 版支援在 Linux、MacOS 和 Windows 上進行開發。Version 2.x supports development on Linux, MacOS, and Windows. 所有環境都依賴 Core Tools 執行本機 Functions 執行階段。All environments rely on Core Tools for the local Functions runtime.
Visual Studio 2019Visual Studio 2019 C# (類別庫)C# (class library) Azure Functions tools 隨附於Azure 開發的工作負載Visual Studio 2019和更新版本。The Azure Functions tools are included in the Azure development workload of Visual Studio 2019 and later versions. 讓您編譯類別庫中的函式,並將 .dll 發佈至 Azure。Lets you compile functions in a class library and publish the .dll to Azure. 包括用於本機測試的 Core Tools。Includes the Core Tools for local testing. 若要深入了解,請參閱使用 Visual Studio 開發 Azure FunctionsTo learn more, see Develop Azure Functions using Visual Studio.
Maven (各種)Maven (various) JavaJava 與 Core Tools 整合以便進行 Java 函式開發。Integrates with Core Tools to enable development of Java functions. 2.x 版支援在 Linux、MacOS 和 Windows 上進行開發。Version 2.x supports development on Linux, MacOS, and Windows. 若要深入了解,請參閱使用 Java 和 Maven 建立您的第一個函式To learn more, see Create your first function with Java and Maven. 也支援使用 EclipseIntelliJ IDEA 進行開發Also supports development using Eclipse and IntelliJ IDEA

重要

請勿在相同函式應用程式中混用本機開發與入口網站開發。Do not mix local development with portal development in the same function app. 當您從本機專案建立及發佈函式時,不應嘗試在入口網站中維護或修改專案程式碼。When you create and publish functions from a local project, you should not try to maintain or modify project code in the portal.

每個本機開發環境都可讓您建立函式應用程式專案,並使用預先定義的 Functions 範本來建立新的函式。Each of these local development environments lets you create function app projects and use predefined Functions templates to create new functions. 每個環境都會使用 Core Tool,以便您在自己的電腦上針對實際的 Functions 執行階段進行您的函式測試和偵錯,就如同處理任何其他應用程式一樣。Each uses the Core Tools so that you can test and debug your functions against the real Functions runtime on your own machine just as you would any other app. 您也可以從上述任何環境將您的函式應用程式專案發佈至 Azure。You can also publish you function app project from any of these environments to Azure.

後續步驟Next steps