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

在本地对 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 扩展在 VS Code 中添加了 Functions 支持。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 工具包含在 Visual Studio 2019 和更高版本的 Azure 开发工作负荷中。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 Tools,使你能够在自己的计算机上针对实际的 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