快速入门:使用 Azure 逻辑应用创建自动化任务、流程和工作流 - Visual StudioQuickstart: Create automated tasks, processes, and workflows with Azure Logic Apps - Visual Studio

可以通过 Azure 逻辑应用和 Visual Studio 创建工作流,以便自动完成用于跨企业和组织集成应用、数据、系统和服务的任务和流程。With Azure Logic Apps and Visual Studio, you can create workflows for automating tasks and processes that integrate apps, data, systems, and services across enterprises and organizations. 本快速入门展示了如何通过在 Visual Studio 中创建逻辑应用并将这些应用部署到 Azure 来设计和构建这些工作流。This quickstart shows how you can design and build these workflows by creating logic apps in Visual Studio and deploying those apps to Azure. 尽管可以在 Azure 门户中执行这些任务,但在需要将逻辑应用添加到源代码管理、发布不同的版本,以及为不同的部署环境创建 Azure 资源管理器模板时,也可以使用 Visual Studio。Although you can perform these tasks in the Azure portal, Visual Studio lets you add your logic apps to source control, publish different versions, and create Azure Resource Manager templates for different deployment environments.

如果不熟悉 Azure 逻辑应用,只希望了解基本概念,则可尝试关于在 Azure 门户中创建逻辑应用的快速入门If you're new to Azure Logic Apps and just want the basic concepts, try the quickstart for creating a logic app in the Azure portal. 逻辑应用设计器在 Azure 门户和 Visual Studio 中的工作方式类似。The Logic App Designer works similarly in both the Azure portal and Visual Studio.

在本快速入门中,你将使用 Visual Studio 创建与 Azure 门户快速入门相同的逻辑应用。In this quickstart, you create the same logic app with Visual Studio as the Azure portal quickstart. 此逻辑应用监视网站的 RSS 源,并针对该源中的每个新项发送电子邮件。This logic app monitors a website's RSS feed and sends email for each new item in that feed. 完成后的逻辑应用看起来与以下概略性的工作流类似:Your finished logic app looks like this high-level workflow:

完成的逻辑应用

先决条件Prerequisites

创建 Azure 资源组项目Create Azure resource group project

若要开始,请创建 Azure 资源组项目To get started, create an Azure Resource Group project. 详细了解 Azure 资源组和资源Learn more about Azure resource groups and resources.

  1. 启动 Visual Studio。Start Visual Studio. 使用 Azure 帐户登录。Sign in with your Azure account.

  2. 在“文件”菜单中,选择“新建” > “项目”。On the File menu, select New > Project. (键盘:Ctrl + Shift + N)(Keyboard: Ctrl + Shift + N)

    在“文件”菜单中,选择“新建”>“项目”。

  3. 在“已安装”下,选择“Visual C#”或“Visual Basic” 。Under Installed, select Visual C# or Visual Basic. 选择“云” > “Azure 资源组”。Select Cloud > Azure Resource Group. 为项目命名,例如:Name your project, for example:

    创建 Azure 资源组项目

    备注

    资源组名称只能包含字母、数字、句点 (.)、下划线 (_)、连字符 (-) 和括号(()),但不能以句点 (.) 结尾。Resource group names can contain only letters, numbers, periods (.), underscores (_), hyphens (-), and parentheses ((, )), but can't end with periods (.).

    如果“云”或“Azure 资源组”未显示,请确保安装 Azure SDK for Visual Studio。 If Cloud or Azure Resource Group doesn't appear, make sure you install the Azure SDK for Visual Studio.

    如果使用 Visual Studio 2019,请执行以下步骤:If you're using Visual Studio 2019, follow these steps:

    1. 在“创建新项目”框中,选择适用于 Visual C# 或 Visual Basic 的“Azure 资源组”项目。 In the Create a new project box, select the Azure Resource Group project for Visual C# or Visual Basic. 选择“下一步”。Select Next.

    2. 提供要使用的 Azure 资源组的名称和其他项目信息。Provide a name for the Azure resource group you want to use and other project information. 选择“创建” 。Select Create.

  4. 在模板列表中,选择“逻辑应用”模板。From the template list, select the Logic App template. 选择“确定” 。Select OK.

    选择逻辑应用模板

    在 Visual Studio 创建项目后,解决方案资源管理器会打开并显示你的解决方案。After Visual Studio creates your project, Solution Explorer opens and shows your solution. 在你的解决方案中,LogicApp.json 文件不仅存储逻辑应用定义,还是一个可以用于部署的 Azure 资源管理器模板。In your solution, the LogicApp.json file not only stores your logic app definition but is also an Azure Resource Manager template that you can use for deployment.

    解决方案资源管理器显示新的逻辑应用解决方案和部署文件

创建空白逻辑应用Create blank logic app

在创建 Azure 资源组项目后,使用空白逻辑应用模板创建你的逻辑应用。When you have your Azure Resource Group project, create your logic app with the Blank Logic App template.

  1. 在解决方案资源管理器中,打开 LogicApp.json 文件的快捷菜单。In Solution Explorer, open the LogicApp.json file's shortcut menu. 选择“使用逻辑应用设计器打开”。Select Open With Logic App Designer. (键盘:Ctrl + L)(Keyboard: Ctrl + L)

    使用逻辑应用设计器打开 LogicApp.json 文件

    提示

    如果你的 Visual Studio 2019 中没有此命令,请检查是否安装了 Visual Studio 的最新更新。If you don't have this command in Visual Studio 2019, check that you have the latest updates for Visual Studio.

    Visual Studio 会提示你提供用于为你的逻辑应用和连接创建并部署资源的 Azure 订阅和 Azure 资源组。Visual Studio prompts you for your Azure subscription and an Azure resource group for creating and deploying resources for your logic app and connections.

  2. 对于“订阅”,请选择你的 Azure 订阅。For Subscription, select your Azure subscription. 对于“资源组”,请选择“新建”以创建其他 Azure 资源组 。For Resource group, select Create New to create another Azure resource group.

    选择 Azure 订阅、资源组和资源位置

    设置Setting 示例值Example value 说明Description
    用户帐户User account FabrikamFabrikam
    sophia-owen@fabrikam.com
    登录 Visual Studio 时使用的帐户The account that you used when you signed in to Visual Studio
    订阅Subscription 标准预付费套餐Standard Pay-in-Advance Offer
    (sophia-owen@fabrikam.com)(sophia-owen@fabrikam.com)
    Azure 订阅的名称以及关联的帐户The name for your Azure subscription and associated account
    资源组Resource Group MyLogicApp-RGMyLogicApp-RG
    (中国北部)(China North)
    用于存储和部署逻辑应用资源的 Azure 资源组和位置The Azure resource group and location for storing and deploying your logic app's resources
    位置Location 与资源组相同Same as Resource Group 用于部署逻辑应用的位置类型和特定位置。The location type and specific location for deploying your logic app. 位置类型可以是 Azure 区域,也可以是现有的集成服务环境 (ISE)。The location type is either an Azure region or an existing integration service environment (ISE).

    对于本快速入门,请将“位置类型”设置为“区域”,并将“位置”设置为“与资源组相同”。For this quickstart, keep the location type set to Region and the location set to Same as Resource Group.

    注意:创建资源组项目后,可以更改位置类型和位置,但不同的位置类型会以不同的方式影响逻辑应用。Note: After you create your resource group project, you can change the location type and the location, but different location type affects your logic app in various ways.

  3. 逻辑应用设计器会打开一个页面,其中显示了介绍视频和常用的触发器。The Logic Apps Designer opens a page that shows an introduction video and commonly used triggers. 向下滚动,越过视频和触发器,找到“模板”,然后选择“空白逻辑应用”。Scroll down past the video and triggers to Templates, and select Blank Logic App.

    选择“空白逻辑应用”

生成逻辑应用工作流Build logic app workflow

接下来,添加一个 RSS 触发器,该触发器在出现新的源项时触发。Next, add an RSS trigger that fires when a new feed item appears. 每个逻辑应用都以触发器开头,该触发器在特定条件得到满足的情况下触发。Every logic app starts with a trigger, which fires when specific criteria is met. 每当触发器触发时,逻辑应用引擎就会创建一个逻辑应用实例来运行工作流。Each time the trigger fires, the Logic Apps engine creates a logic app instance that runs your workflow.

  1. 在逻辑应用设计器的搜索框下,选择“全部”。In Logic App Designer, under the search box, select All. 在搜索框中输入“rss”。In the search box, enter "rss". 从触发器列表中选择此触发器:发布源项时From the triggers list, select this trigger: When a feed item is published

    通过添加触发器和操作来生成逻辑应用

  2. 在触发器出现在设计器中后,通过执行 Azure 门户快速入门中的工作流步骤来完成逻辑应用的构建。After the trigger appears in the designer, finish building the logic app by following the workflow steps in the Azure portal quickstart, then return to this article. 完成后,逻辑应用如以下示例所示:When you're done, your logic app looks like this example:

    完成的逻辑应用

  3. 保存你的 Visual Studio 解决方案。Save your Visual Studio solution. (键盘:Ctrl + S)(Keyboard: Ctrl + S)

将逻辑应用部署到 AzureDeploy logic app to Azure

必须先将逻辑应用从 Visual Studio 部署到 Azure,然后才能运行并测试逻辑应用。Before you can run and test your logic app, deploy the app to Azure from Visual Studio.

  1. 在解决方案资源管理器的项目快捷菜单中,选择“部署” > “新建”。In Solution Explorer, on your project's shortcut menu, select Deploy > New. 如果出现系统提示,请使用 Azure 帐户登录。If prompted, sign in with your Azure account.

    创建逻辑应用部署

  2. 就此部署来说,请保留默认的 Azure 订阅、资源组和其他设置。For this deployment, keep the default Azure subscription, resource group, and other settings. 选择“部署”。Select Deploy.

    将逻辑应用部署到 Azure 资源组

  3. 如果“编辑参数”框出现,请为你的逻辑应用提供一个资源名称。If the Edit Parameters box appears, provide a resource name for your logic app. 保存设置。Save your settings.

    提供逻辑应用的部署名称

    部署开始时,应用的部署状态显示在 Visual Studio 的“输出”窗口中。When deployment starts, your app's deployment status appears in the Visual Studio Output window. 如果状态不显示,请打开“显示输出来源”列表,然后选择 Azure 资源组。If the status doesn't appear, open the Show output from list, and select your Azure resource group.

    部署状态输出

    如果所选连接器需要你提供输入,则会在背景中打开一个 PowerShell 窗口,提示你输入必需的密码或机密密钥。If your selected connectors need input from you, a PowerShell window opens in the background and prompts for any necessary passwords or secret keys. 输入该信息后,部署会继续。After you enter this information, deployment continues.

    PowerShell 窗口

    在部署完成后,你的逻辑应用会出现在 Azure 门户中,并会根据指定的计划(每隔一分钟)运行。After deployment finishes, your logic app is live in the Azure portal and runs on your specified schedule (every minute). 如果该触发器发现新的源项,则触发器会激发,这将创建运行你的逻辑应用操作的一个工作流实例。If the trigger finds new feed items, the trigger fires, which creates a workflow instance that runs your logic app's actions. 你的逻辑应用会针对每个新项发送电子邮件。Your logic app sends email for each new item. 反之,如果触发器未发现新项,则触发器不会激发,而是“跳过”工作流实例化。Otherwise, if the trigger doesn't find new items, the trigger doesn't fire and "skips" instantiating the workflow. 逻辑应用会等到下一个间隔过后才进行检查。Your logic app waits until the next interval before checking.

    下面是此逻辑应用发送的示例电子邮件。Here are sample emails that this logic app sends. 如果没有收到任何电子邮件,请检查垃圾邮件文件夹。If you don't get any emails, check your junk email folder.

    Outlook 针对每个新的 RSS 项发送电子邮件

祝贺你,你已使用 Visual Studio 成功生成并部署了逻辑应用。Congratulations, you've successfully built and deployed your logic app with Visual Studio. 若要管理逻辑应用并查看其运行历史记录,请参阅使用 Visual Studio 管理逻辑应用To manage your logic app and review its run history, see Manage logic apps with Visual Studio.

添加新逻辑应用Add new logic app

如果你有现有的 Azure 资源组项目,则可以使用“JSON 大纲”窗口向该项目添加一个新的空白逻辑应用。When you have an existing Azure Resource Group project, you can add a new blank logic app to that project by using the JSON Outline window.

  1. 在“解决方案资源管理器”中,打开 <logic-app-name>.json 文件。In Solution Explorer, open the <logic-app-name>.json file.

  2. 在“视图”菜单中,选择“其他窗口” > “JSON 大纲”。 From the View menu, select Other Windows > JSON Outline.

  3. 若要将资源添加到模板文件,请在“JSON 大纲”窗口顶部选择“添加资源”。To add a resource to the template file, select Add Resource at the top of the JSON Outline window. 或者在“JSON 大纲”窗口中,打开“资源”快捷菜单,并选择“添加新资源” 。Or in the JSON Outline window, open the resources shortcut menu, and select Add New Resource.

    “JSON 大纲”窗口

  4. 在“添加资源”对话框中,在搜索框中,找到 logic app 并选择“逻辑应用” 。In the Add Resource dialog box, in the search box, find logic app, and select Logic App. 为逻辑应用命名,并选择“添加”。Name your logic app, and select Add.

    添加资源

清理资源Clean up resources

完成逻辑应用后,删除包含你的逻辑应用和相关资源的资源组。When you're done with your logic app, delete the resource group that contains your logic app and related resources.

  1. 使用创建逻辑应用时所使用的帐户登录到 Azure 门户Sign in to the Azure portal with the same account used to create your logic app.

  2. 在 Azure 门户菜单上,选择“资源组”或从任意页面搜索并选择“资源组” 。On the Azure portal menu, select Resource groups, or search for and select Resource groups from any page. 选择逻辑应用的资源组。Select your logic app's resource group.

  3. 在“概述”页上,选择“删除资源组” 。On the Overview page, select Delete resource group. 输入资源组名称作为确认,然后选择“删除”。Enter the resource group name as confirmation, and select Delete.

    “资源组”>“概览”>“删除资源组”

  4. 从本地计算机删除 Visual Studio 解决方案。Delete the Visual Studio solution from your local computer.

后续步骤Next steps

本文介绍了如何使用 Visual Studio 生成、部署和运行逻辑应用。In this article, you built, deployed, and ran your logic app with Visual Studio. 若要了解如何使用 Visual Studio 管理和执行逻辑应用的高级部署,请参阅以下文章:To learn about managing and performing advanced deployment for logic apps with Visual Studio, see these articles: