使用 Azure Functions 开发和发布 .NET 5 函数Develop and publish .NET 5 functions using Azure Functions

本文介绍如何使用 .NET 5.0 来处理 C# 函数,后者在 Azure Functions 运行时的进程外运行。This article shows you how to work with C# functions using .NET 5.0, which run out-of-process from the Azure Functions runtime. 你将了解如何在本地创建、调试这些 .NET 隔离进程函数,以及如何将其发布到 Azure。You'll learn how to create, debug locally, and publish these .NET isolated process functions to Azure. 在 Azure 中,这些函数在支持 .NET 5.0 的隔离进程中运行。In Azure, these functions run in an isolated process that supports .NET 5.0. 若要了解详细信息,请参阅有关在 Azure 中的 .NET 5.0 上运行函数的指南To learn more, see Guide for running functions on .NET 5.0 in Azure.

如果你不需要支持 .NET 5.0 或者在进程外运行函数,可以改为创建 C# 类库函数If you don't need to support .NET 5.0 or run your functions out-of-process, you might want to instead create a C# class library function.

备注

当前不支持在 Azure 门户中开发 .NET 隔离进程函数。Developing .NET isolated process functions in the Azure portal isn't currently supported. 必须使用 Azure CLI 或 Visual Studio Code 发布才能在 Azure 中创建支持在进程外运行 .NET 5.0 应用的函数应用。You must use either the Azure CLI or Visual Studio Code publishing to create a function app in Azure that supports running .NET 5.0 apps out-of-process.

先决条件Prerequisites

  • Visual Studio 2019,包括 Azure 开发 工作负荷。Visual Studio 2019, including the Azure development workload.
    .NET 隔离函数项目模板和发布目前在 Visual Studio 中不可用。.NET isolated function project templates and publishing aren't currently available in Visual Studio.

创建本地函数项目Create a local function project

在 Azure Functions 中,有一个函数项目是一个或多个单独函数(每个函数响应特定的触发器)的容器。In Azure Functions, a function project is a container for one or more individual functions that each responds to a specific trigger. 项目中的所有函数共享相同的本地和宿主配置。All functions in a project share the same local and hosting configurations. 在本部分,你将创建包含单个函数的函数项目。In this section, you create a function project that contains a single function.

备注

目前没有支持创建 .NET 隔离函数项目的 Visual Studio 项目模板。At this time, there are no Visual Studio project templates that support creating .NET isolated function projects. 本文介绍如何使用 Core Tools 创建 C# 项目,然后在本地运行该项目,并在 Visual Studio 中对其进行调试。This article shows you how to use Core Tools to create your C# project, which you can then run locally and debug in Visual Studio.

  1. 在活动栏中选择“Azure”图标,然后在“Azure:函数”区域中选择“创建新项目...”图标。Choose the Azure icon in the Activity bar, then in the Azure: Functions area, select the Create new project... icon.

    选择“创建新项目”

  2. 为项目工作区选择目录位置,然后选择“选择” 。Choose a directory location for your project workspace and choose Select.

    备注

    这些步骤已设计为在工作区之外完成。These steps were designed to be completed outside of a workspace. 在这种情况下,请不要选择属于工作区内的项目文件夹。In this case, do not select a project folder that is part of a workspace.

  3. 根据提示提供以下信息:Provide the following information at the prompts:

    • 选择函数项目的语言:选择C#Select a language for your function project: Choose C#.

    • 选择 .NET 运行时:选择“.NET 5 isolated”。Select a .NET runtime: Choose .NET 5 isolated.

    • 为项目的第一个函数选择模板:选择HTTP triggerSelect a template for your project's first function: Choose HTTP trigger.

    • 提供函数名称:键入 HttpExampleProvide a function name: Type HttpExample.

    • 提供命名空间:键入 My.FunctionsProvide a namespace: Type My.Functions.

    • 授权级别:选择 Anonymous,这使任何人都可以调用你的函数终结点。Authorization level: Choose Anonymous, which enables anyone to call your function endpoint. 若要了解授权级别,请参阅授权密钥To learn about authorization level, see Authorization keys.

    • 选择打开项目的方式:选择Add to workspaceSelect how you would like to open your project: Choose Add to workspace.

  4. Visual Studio Code 将使用此信息生成一个包含 HTTP 触发器的 Azure Functions 项目。Using this information, Visual Studio Code generates an Azure Functions project with an HTTP trigger. 可以在资源管理器中查看本地项目文件。You can view the local project files in the Explorer. 若要详细了解所创建的文件,请参阅生成的项目文件To learn more about files that are created, see Generated project files.

  1. 按如下所示运行 func init 命令,在名为 LocalFunctionProj 的文件夹中创建函数项目:Run the func init command, as follows, to create a functions project in a folder named LocalFunctionProj:

    func init LocalFunctionProj --worker-runtime dotnetisolated
    

    指定 dotnetisolated 将创建在 .NET 5.0 上运行的项目。Specifying dotnetisolated creates a project that runs on .NET 5.0.

  2. 导航到项目文件夹:Navigate into the project folder:

    cd LocalFunctionProj
    

    此文件夹包含项目的各个文件,其中包括 local.settings.jsonhost.json 配置文件。This folder contains various files for the project, including the local.settings.json and host.json configurations files. 由于 local.settings.json 可以包含从 Azure 下载的机密,因此,默认情况下,该文件会从 .gitignore 文件的源代码管理中排除。Because local.settings.json can contain secrets downloaded from Azure, the file is excluded from source control by default in the .gitignore file.

  3. 使用以下命令将一个函数添加到项目,其中,--name 参数是该函数 (HttpExample) 的唯一名称,--template 参数指定该函数的触发器 (HTTP)。Add a function to your project by using the following command, where the --name argument is the unique name of your function (HttpExample) and the --template argument specifies the function's trigger (HTTP).

    func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"
    

    func new 创建 HttpExample.cs 代码文件。func new creates an HttpExample.cs code file.

在本地运行函数Run the function locally

Visual Studio Code 与 Azure Functions Core Tools 相集成,便于你在发布到 Azure 之前在本地开发计算机上运行此项目。Visual Studio Code integrates with Azure Functions Core tools to let you run this project on your local development computer before you publish to Azure.

  1. 若要调用函数,请按 F5 启动函数应用项目To call your function, press F5 to start the function app project. 来自 Core Tools 的输出会显示在“终端”面板中。Output from Core Tools is displayed in the Terminal panel. 应用将在“终端”面板中启动。Your app starts in the Terminal panel. 可以看到 HTTP 触发函数的 URL 终结点在本地运行。You can see the URL endpoint of your HTTP-triggered function running locally.

    本地函数 VS Code 输出

    如果在 Windows 上运行时遇到问题,请确保用于 Visual Studio Code 的默认终端未设置为“WSL Bash”。If you have trouble running on Windows, make sure that the default terminal for Visual Studio Code isn't set to WSL Bash.

  2. 运行 Core Tools 后,转到“Azure: Functions”区域。With Core Tools running, go to the Azure: Functions area. 在“Functions”下,展开“本地项目” > “Functions” 。Under Functions, expand Local Project > Functions. 右键单击 (Windows) 或按 Ctrl - 单击 (macOS) HttpExample 函数,然后选择“立即执行函数...”。Right-click (Windows) or Ctrl - click (macOS) the HttpExample function and choose Execute Function Now....

    立即在 Visual Studio Code 中执行函数

  3. 在“输入请求正文”中,你将看到请求消息正文值 { "name": "Azure" }In Enter request body you see the request message body value of { "name": "Azure" }. 按 Enter 将此请求消息发送给函数。Press Enter to send this request message to your function.

    可以改为将 HTTP GET 请求发送到 Web 浏览器中的 http://localhost:7071/api/HttpExample 地址。You could have instead sent an HTTP GET request to the http://localhost:7071/api/HttpExample address in a web browser.

  4. 当函数在本地执行并返回响应时,Visual Studio Code 中将引发通知。When the function executes locally and returns a response, a notification is raised in Visual Studio Code. 函数执行的相关信息将显示在“终端”面板中。Information about the function execution is shown in Terminal panel.

  5. 按 Ctrl + C 停止 Core Tools 并断开调试器的连接Press Ctrl + C to stop Core Tools and disconnect the debugger.

在本地运行函数Run the function locally

  1. 通过从 LocalFunctionProj 文件夹启动本地 Azure Functions 运行时主机来运行函数:Run your function by starting the local Azure Functions runtime host from the LocalFunctionProj folder:

    func start
    

    在输出的末尾,应显示以下行:Toward the end of the output, the following lines should appear:

     ...
    
     Now listening on: http://0.0.0.0:7071
     Application started. Press Ctrl+C to shut down.
    
     Http Functions:
    
             HttpExample: [GET,POST] http://localhost:7071/api/HttpExample
     ...
    
     

    备注

    如果 HttpExample 未按如上所示出现,则可能是在项目的根文件夹外启动了主机。If HttpExample doesn't appear as shown above, you likely started the host from outside the root folder of the project. 在这种情况下,请按 Ctrl+C 停止主机,导航到项目的根文件夹,然后重新运行上一命令。In that case, use Ctrl+C to stop the host, navigate to the project's root folder, and run the previous command again.

  2. 将此输出中 HttpExample 函数的 URL 复制到浏览器,并追加查询字符串 ?name=<YOUR_NAME>,使完整 URL 类似于 http://localhost:7071/api/HttpExample?name=FunctionsCopy the URL of your HttpExample function from this output to a browser and append the query string ?name=<YOUR_NAME>, making the full URL like http://localhost:7071/api/HttpExample?name=Functions. 浏览器应会显示类似于 Hello Functions 的消息:The browser should display a message like Hello Functions:

    在浏览器中本地运行函数后的结果

  3. 当你发出请求时,启动项目时所在的终端还会显示日志输出。The terminal in which you started your project also shows log output as you make requests.

  4. 完成后,请按 Ctrl+C 并选择 y 以停止函数主机 。When you're done, use Ctrl+C and choose y to stop the functions host.

在本地运行函数Run the function locally

此时,你可以从项目文件夹的根目录运行 func start 命令,以编译和运行 C# 隔离函数项目。At this point, you can run the func start command from the root of your project folder to compile and run the C# isolated functions project. 目前,如果要在 Visual Studio 中调试进程外函数代码,则需要使用以下步骤手动将调试程序附加到正在运行的 Functions 运行时进程:Currently, if you want to debug your out-of-process function code in Visual Studio, you need to manually attach a debugger to the running Functions runtime process by using the following steps:

  1. 在 Visual Studio 中打开项目文件 (.csproj)。Open the project file (.csproj) in Visual Studio. 你可以查看和修改项目代码,并在代码中设置所需的断点。You can review and modify your project code and set any desired break points in the code.

  2. 通过根项目文件夹在终端或命令提示符窗口中使用以下命令启动运行时主机:From the root project folder, use the following command from the terminal or a command prompt to start the runtime host:

    func start --dotnet-isolated-debug
    

    --dotnet-isolated-debug 选项指示进程在继续之前等待调试程序进行连接。The --dotnet-isolated-debug option tells the process to wait for a debugger to attach before continuing. 在输出的末尾,你应该会看到类似于以下行的内容:Towards the end of the output, you should see something like the following lines:

     ...
    
     Functions:
    
         HttpExample: [GET,POST] http://localhost:7071/api/HttpExample
    
     For detailed output, run func with --verbose flag.
     [2021-03-09T08:41:41.904Z] Azure Functions .NET Worker (PID: 81720) initialized in debug mode. Waiting for debugger to attach...
     ...
    
     

    PID: XXXXXX 指示 dotnet.exe 进程(正在运行的 Functions 主机)的进程 ID (PID)。The PID: XXXXXX indicates the process ID (PID) of the dotnet.exe process that is the running Functions host.

  3. 在 Azure Functions 运行时输出中,记下主机进程的进程 ID,以便将调试程序附加到该进程。In the Azure Functions runtime output, make a note of the process ID of the host process, to which you'll attach a debugger. 另请记下本地函数的 URL。Also note the URL of your local function.

  4. 在 Visual Studio 的“调试”菜单中,选择“附加到进程...”,找到与进程 ID 匹配的进程,然后选择“附加”。From the Debug menu in Visual Studio, select Attach to Process..., locate the process that matches the process ID, and select Attach.

    将调试程序附加到 Functions 主机进程

    附加调试程序后,即可像平常一样调试函数代码。With the debugger attached you can debug your function code as normal.

  5. 在浏览器的地址栏中,键入你的本地函数 URL(如下所示),然后运行请求。Into your browser's address bar, type your local function URL, which looks like the following, and run the request.

    http://localhost:7071/api/HttpExample

    此时应该会看到已写入到正在运行的终端的请求的跟踪输出。You should see trace output from the request written to the running terminal. 代码执行在你在函数代码中设置的任意断点处停止。Code execution stops at any break points you set in your function code.

  6. 完成后,请转到终端,按 Ctrl + C 停止主机进程。When you're done, go to the terminal and press Ctrl + C to stop the host process.

确认该函数可以在本地计算机上正确运行以后,即可将项目发布到 Azure。After you've verified that the function runs correctly on your local computer, it's time to publish the project to Azure.

备注

Visual Studio 发布当前不适用于 .NET 隔离进程应用。Visual Studio publishing isn't currently available for .NET isolated process apps. 在 Visual Studio 中完成项目开发后,必须使用 Azure CLI 创建远程 Azure 资源。After you've finished developing your project in Visual Studio, you must use the Azure CLI to create the remote Azure resources. 然后,可以再次在命令行中使用 Azure Functions Core Tools 将项目发布到 Azure。Then, you can again use Azure Functions Core Tools from the command line to publish your project to Azure.

创建函数的支持性 Azure 资源Create supporting Azure resources for your function

在将函数代码部署到 Azure 之前,需要创建三个资源:Before you can deploy your function code to Azure, you need to create three resources:

  • 一个资源组:相关资源的逻辑容器。A resource group, which is a logical container for related resources.
  • 一个存储帐户:用于维护有关函数的状态和其他信息。A Storage account, which is used to maintain state and other information about your functions.
  • 一个函数应用:提供用于执行函数代码的环境。A function app, which provides the environment for executing your function code. 函数应用映射到本地函数项目,可让你将函数分组为一个逻辑单元,以便更轻松地管理、部署和共享资源。A function app maps to your local function project and lets you group functions as a logical unit for easier management, deployment, and sharing of resources.

使用以下命令创建这些项。Use the following commands to create these items.

  1. 请登录到 Azure(如果尚未这样做):If you haven't done so already, sign in to Azure:

    az login
    

    使用 az login 命令登录到 Azure 帐户。The az login command signs you into your Azure account.

  2. chinanorth2 区域中创建名为 AzureFunctionsQuickstart-rg 的资源组:Create a resource group named AzureFunctionsQuickstart-rg in the chinanorth2 region:

    az group create --name AzureFunctionsQuickstart-rg --location chinanorth2
    

    az group create 命令可创建资源组。The az group create command creates a resource group. 通常,你会在从 az account list-locations 命令返回的、离你近的某个可用区域中创建资源组和资源。You generally create your resource group and resources in a region near you, using an available region returned from the az account list-locations command.

  3. 在资源组和区域中创建常规用途存储帐户:Create a general-purpose storage account in your resource group and region:

    az storage account create --name <STORAGE_NAME> --location chinanorth2 --resource-group AzureFunctionsQuickstart-rg --sku Standard_LRS
    

    az storage account create 命令可创建存储帐户。The az storage account create command creates the storage account.

    在上一个示例中,将 <STORAGE_NAME> 替换为适合你且在 Azure 存储中唯一的名称。In the previous example, replace <STORAGE_NAME> with a name that is appropriate to you and unique in Azure Storage. 名称只能包含 3 到 24 个数字和小写字母字符。Names must contain three to 24 characters numbers and lowercase letters only. Standard_LRS 指定 Functions 支持的常规用途帐户。Standard_LRS specifies a general-purpose account, which is supported by Functions.

  4. 在 Azure 中创建函数应用:Create the function app in Azure:

    az functionapp create --resource-group AzureFunctionsQuickstart-rg --consumption-plan-location chinanorth2 --runtime dotnet-isolated --runtime-version 5.0 --functions-version 3 --name <APP_NAME> --storage-account <STORAGE_NAME>
    

    az functionapp create 命令可在 Azure 中创建函数应用。The az functionapp create command creates the function app in Azure.

    在上一个示例中,请将 <STORAGE_NAME> 替换为在上一步骤中使用的帐户的名称,并将 <APP_NAME> 替换为适合自己的全局唯一名称。In the previous example, replace <STORAGE_NAME> with the name of the account you used in the previous step, and replace <APP_NAME> with a globally unique name appropriate to you. <APP_NAME> 也是函数应用的默认 DNS 域。The <APP_NAME> is also the default DNS domain for the function app.

    此命令会创建一个函数应用,该应用运行 Azure Functions 消耗计划中的 .NET 5.0。This command creates a function app running .NET 5.0 under the Azure Functions Consumption Plan. 就本文中的操作产生的用量来说,此计划应该是免费的。This plan should be free for the amount of usage you incur in this article. 此命令还在同一资源组中预配关联的 Azure Application Insights 实例。The command also provisions an associated Azure Application Insights instance in the same resource group. 使用该实例可以监视函数应用并查看日志。Use this instance to monitor your function app and view logs. 有关详细信息,请参阅监视 Azure FunctionsFor more information, see Monitor Azure Functions. 该实例在激活之前不会产生费用。The instance incurs no costs until you activate it.

将函数项目部署到 AzureDeploy the function project to Azure

在 Azure 中成功创建函数应用后,便可以使用 func azure functionapp publish 命令部署本地函数项目。After you've successfully created your function app in Azure, you're now ready to deploy your local functions project by using the func azure functionapp publish command.

在以下示例中,请将 <APP_NAME> 替换为你的应用的名称。In the following example, replace <APP_NAME> with the name of your app.

func azure functionapp publish <APP_NAME>

publish 命令显示类似于以下输出的结果(为简洁起见,示例中的结果已截断):The publish command shows results similar to the following output (truncated for simplicity):

...

Getting site publishing info...
Creating archive for current directory...
Performing remote build for functions project.

...

Deployment successful.
Remote build succeeded!
Syncing triggers...
Functions in msdocs-azurefunctions-qs:
    HttpExample - [httpTrigger]
        Invoke url: https://msdocs-azurefunctions-qs.chinacloudsites.cn/api/httpexample

登录 AzureSign in to Azure

在发布应用之前,必须先登录到 Azure。Before you can publish your app, you must sign in to Azure.

  1. 打开 Visual Studio Code,然后单击 View -> Command Palette...Open Visual Studio Code, click View -> Command Palette....

  2. 输入 Sign In to Azure Cloud,以搜索 Azure 中国环境。Input Sign In to Azure Cloud to search Azure China Environment.

  3. 在搜索结果中单击 Azure ChinaClick Azure China in search result.

  4. 窗口的右下角将出现一个弹出窗口。You will find a popup window at the bottom right of your window.

    弹出窗口

  5. 打开页面 **https://microsoft.com/deviceloginchina**,然后输入该代码进行身份验证。Open the page https://microsoft.com/deviceloginchina and enter the code to authenticate.

将项目发布到 AzurePublish the project to Azure

在本部分,你将在 Azure 订阅中创建一个函数应用和相关资源,然后部署代码。In this section, you create a function app and related resources in your Azure subscription and then deploy your code.

重要

发布到现有函数应用将覆盖该应用在 Azure 中的内容。Publishing to an existing function app overwrites the content of that app in Azure.

  1. 在活动栏中选择“Azure”图标,然后在“Azure:函数”区域中,选择“部署到函数应用...”按钮。Choose the Azure icon in the Activity bar, then in the Azure: Functions area, choose the Deploy to function app... button.

    将项目发布到 Azure

  2. 根据提示提供以下信息:Provide the following information at the prompts:

    • 选择文件夹:从工作区中选择一个文件夹,或浏览到包含函数应用的文件夹。Select folder: Choose a folder from your workspace or browse to one that contains your function app. 如果已打开有效的函数应用,则不会看到此提示。You won't see this prompt when you already have a valid function app opened.

    • 选择订阅:选择要使用的订阅。Select subscription: Choose the subscription to use. 如果只有一个订阅,则不会看到此提示。You won't see this prompt when you only have one subscription.

    • 在 Azure 中选择函数应用:选择- Create new Function AppSelect Function App in Azure: Choose - Create new Function App. (请不要选择本文中未介绍的 Advanced 选项。)(Don't choose the Advanced option, which isn't covered in this article.)

    • 输入函数应用的全局唯一名称:键入在 URL 路径中有效的名称。Enter a globally unique name for the function app: Type a name that is valid in a URL path. 将对你键入的名称进行验证,以确保其在 Azure Functions 中是唯一的。The name you type is validated to make sure that it's unique in Azure Functions.

    • 选择运行时堆栈:选择.NET 5 (non-LTS)Select a runtime stack: Choose .NET 5 (non-LTS).

    • 选择新资源的位置:为了获得更好的性能,请选择你附近的 区域Select a location for new resources: For better performance, choose a region near you.

    在 Azure 中创建单个资源时,你会在通知区域中看到这些资源的状态。In the notification area, you see the status of individual resources as they're created in Azure.

    Azure 资源创建通知

  3. 完成后,将使用基于函数应用名称的名称在订阅中创建以下 Azure 资源:When completed, the following Azure resources are created in your subscription, using names based on your function app name:

    • 一个资源组:相关资源的逻辑容器。A resource group, which is a logical container for related resources.
    • 一个标准 Azure 存储帐户:用于维护项目的状态和其他信息。A standard Azure Storage account, which maintains state and other information about your projects.
    • 一个消耗计划:用于定义无服务器函数应用的基础主机。A consumption plan, which defines the underlying host for your serverless function app.
    • 一个函数应用:提供用于执行函数代码的环境。A function app, which provides the environment for executing your function code. 可以通过函数应用将函数分组为逻辑单元,以便在同一托管计划中更轻松地管理、部署和共享资源。A function app lets you group functions as a logical unit for easier management, deployment, and sharing of resources within the same hosting plan.
    • 一个连接到函数应用的 Application Insights 实例:用于跟踪无服务器函数的使用情况。An Application Insights instance connected to the function app, which tracks usage of your serverless function.

    创建函数应用并应用了部署包之后,会显示一个通知。A notification is displayed after your function app is created and the deployment package is applied.

    提示

    默认情况下,会根据你提供的函数应用名称创建函数应用所需的 Azure 资源。By default, the Azure resources required by your function app are created based on the function app name you provide. 默认情况下,还会在函数应用所在的新资源组中创建这些资源。By default, they are also created in the same new resource group with the function app. 如果要自定义这些资源的名称或重复使用现有资源,则需要使用高级创建选项来发布项目If you want to either customize the names of these resources or reuse existing resources, you need to instead publish the project with advanced create options.

  4. 在此通知中选择“查看输出”以查看创建和部署结果,其中包括你创建的 Azure 资源。Select View Output in this notification to view the creation and deployment results, including the Azure resources that you created. 如果错过了通知,请选择右下角的响铃图标以再次查看。If you miss the notification, select the bell icon in the lower right corner to see it again.

    创建完成通知

在 Azure 上调用函数Invoke the function on Azure

由于函数使用 HTTP 触发器,因此,可以通过在浏览器中或使用 curl 等工具,向此函数的 URL 发出 HTTP 请求来调用它。Because your function uses an HTTP trigger, you invoke it by making an HTTP request to its URL in the browser or with a tool like curl.

将 publish 命令的输出中显示的完整“调用 URL”复制到浏览器的地址栏,并追加查询参数 &name=FunctionsCopy the complete Invoke URL shown in the output of the publish command into a browser address bar, appending the query parameter &name=Functions. 浏览器显示的输出应与本地运行函数时显示的输出类似。The browser should display similar output as when you ran the function locally.

在 Azure 中运行函数Run the function in Azure

  1. 返回到“Azure:函数”区域(位于侧栏中),然后展开你的订阅、新的函数应用和“函数”。Back in the Azure: Functions area in the side bar, expand your subscription, your new function app, and Functions. 右键单击 (Windows) 或按 Ctrl - 单击 (macOS) HttpExample 函数,然后选择“立即执行函数...”。Right-click (Windows) or Ctrl - click (macOS) the HttpExample function and choose Execute Function Now....

    立即在 Azure 的 Visual Studio Code 中执行函数

  2. 在“输入请求正文”中,你将看到请求消息正文值 { "name": "Azure" }In Enter request body you see the request message body value of { "name": "Azure" }. 按 Enter 将此请求消息发送给函数。Press Enter to send this request message to your function.

  3. 当函数在 Azure 中执行并返回响应时,Visual Studio Code 中将引发通知。When the function executes in Azure and returns a response, a notification is raised in Visual Studio Code.

清理资源Clean up resources

你创建了完成本文所需的资源。You created resources to complete this article. 这些资源可能需要付费,具体取决于帐户状态服务定价You may be billed for these resources, depending on your account status and service pricing.

请使用以下命令删除资源组及其包含的所有资源,以免产生额外的费用。Use the following command to delete the resource group and all its contained resources to avoid incurring further costs.

az group delete --name AzureFunctionsQuickstart-rg

请使用以下步骤删除函数应用及其相关资源,以免产生任何额外的费用。Use the following steps to delete the function app and its related resources to avoid incurring any further costs.

  1. 在 Visual Studio Code 中,按 F1 打开命令面板In Visual Studio Code, press F1 to open the command palette. 在命令面板中,搜索并选择 Azure Functions: Open in portalIn the command palette, search for and select Azure Functions: Open in portal.

  2. 选择你的函数应用,然后按 EnterChoose your function app, and press Enter. 随即将在 Azure 门户中打开函数应用页面。The function app page opens in the Azure portal.

  3. 在“概览”选项卡中,选择“资源组”旁边的命名链接。In the Overview tab, select the named link next to Resource group.

    从函数应用页选择要删除的资源组。

  4. 在“资源组”页中查看所包括的资源的列表,然后验证这些资源是否是要删除的。In the Resource group page, review the list of included resources, and verify that they are the ones you want to delete.

  5. 选择“删除资源组”,然后按说明操作。Select Delete resource group, and follow the instructions.

    可能需要数分钟才能删除完毕。Deletion may take a couple of minutes. 完成后会显示一个通知,持续数秒。When it's done, a notification appears for a few seconds. 也可以选择页面顶部的钟形图标来查看通知。You can also select the bell icon at the top of the page to view the notification.

请使用以下步骤删除函数应用及其相关资源,以免产生任何额外的费用。Use the following steps to delete the function app and its related resources to avoid incurring any further costs.

  1. 在 Cloud Explorer 中,请依次展开你的订阅>“应用服务”,右键单击函数应用,然后选择“在门户中打开” 。In the Cloud Explorer, expand your subscription > App Services, right-click your function app, and choose Open in Portal.

  2. 在函数应用页中,请选择“概览”选项卡,然后选择“资源组”下的链接 。In the function app page, select the Overview tab and then select the link under Resource group.

    从函数应用页选择要删除的资源组

  3. 在“资源组”页中查看所包括的资源的列表,然后验证这些资源是否是要删除的。In the Resource group page, review the list of included resources, and verify that they're the ones you want to delete.

  4. 选择“删除资源组”,然后按说明操作。Select Delete resource group, and follow the instructions.

    可能需要数分钟才能删除完毕。Deletion may take a couple of minutes. 完成后会显示一个通知,持续数秒。When it's done, a notification appears for a few seconds. 也可以选择页面顶部的钟形图标来查看通知。You can also select the bell icon at the top of the page to view the notification.

后续步骤Next steps