使用 Visual Studio 管理逻辑应用Manage logic apps with Visual Studio

尽管可以在 Azure 门户中创建、编辑、管理和部署逻辑应用,但在需要将逻辑应用添加到源代码管理、发布不同的版本,以及为各种部署环境创建 Azure 资源管理器模板时,也可以使用 Visual Studio。Although you can create, edit, manage, and deploy logic apps in the Azure portal, you can also use Visual Studio when you want to add your logic apps to source control, publish different versions, and create Azure Resource Manager templates for various deployment environments. 使用 Visual Studio Cloud Explorer 可以查找和管理逻辑应用以及其他 Azure 资源。With Visual Studio Cloud Explorer, you can find and manage your logic apps along with other Azure resources. 例如,可以打开、下载、编辑、运行、禁用和启用已在 Azure 门户中部署的逻辑应用,以及查看其运行历史记录。For example, you can open, download, edit, run, view run history, disable, and enable logic apps that are already deployed in the Azure portal. 如果你还不太熟悉如何在 Visual Studio 中处理 Azure 逻辑应用,请参阅如何使用 Visual Studio 创建逻辑应用If you're new to working with Azure Logic Apps in Visual Studio, learn how to create logic apps with Visual Studio.

还可以在 Azure 门户中管理逻辑应用You can also manage your logic apps in the Azure portal.

重要

从 Visual Studio 部署或发布逻辑应用会覆盖该应用在 Azure 门户中的版本。Deploying or publishing a logic app from Visual Studio overwrites the version of that app in the Azure portal. 因此,若要在 Azure 门户进行更改并保存这些更改,请务必通过 Azure 门户刷新 Visual Studio 中的逻辑应用,然后,便可以通过 Visual Studio 部署或发布该应用。So if you make changes in the Azure portal that you want to keep, make sure that you refresh the logic app in Visual Studio from the Azure portal before the next time you deploy or publish from Visual Studio.

先决条件Prerequisites

查找逻辑应用Find your logic apps

在 Visual Studio 中,可以使用 Cloud Explorer 来查找与 Azure 订阅关联的,以及在 Azure 门户中部署的所有逻辑应用。In Visual Studio, you can find all the logic apps that are associated with your Azure subscription and are deployed in the Azure portal by using Cloud Explorer.

  1. 打开 Visual Studio。Open Visual Studio. 在“视图”菜单中选择“Cloud Explorer”。On the View menu, select Cloud Explorer.

  2. 在 Cloud Explorer 中选择“帐户管理”。In Cloud Explorer, select Account Management. 选择与逻辑应用关联的 Azure 订阅,然后选择“应用”。Select the Azure subscription associated with your logic apps, and then select Apply. 例如:For example:

    选择“帐户管理”

  3. 根据搜索依据是“资源组”还是“资源类型”执行以下步骤: Based on whether you're searching by Resource Groups or Resource Types, follow these steps:

    • 资源组:Cloud Explorer 会在 Azure 订阅下显示与该订阅关联的所有资源组。Resource Groups: Under your Azure subscription, Cloud Explorer shows all the resource groups that are associated with that subscription. 展开包含你的逻辑应用的资源组,然后选择你的逻辑应用。Expand the resource group that contains your logic app, and then select your logic app.

    • 资源类型:在 Azure 订阅下展开“逻辑应用”。Resource Types: Under your Azure subscription, expand Logic Apps. 在 Cloud Explorer 显示与订阅关联的所有已部署逻辑应用后,请选择自己的逻辑应用。After Cloud Explorer shows all the deployed logic apps that are associated with your subscription, select your logic app.

在 Visual Studio 中打开Open in Visual Studio

在 Visual Studio 中,可以打开以前直接通过 Azure 门户或者使用 Visual Studio 作为 Azure 资源组项目创建和部署的逻辑应用。In Visual Studio, you can open logic apps previously created and deployed either directly through the Azure portal or as Azure Resource Group projects with Visual Studio.

  1. 打开 Cloud Explorer 并找到自己的逻辑应用。Open Cloud Explorer, and find your logic app.

  2. 在逻辑应用的快捷菜单中,选择“使用逻辑应用编辑器打开”。On the logic app's shortcut menu, select Open with Logic App Editor.

    提示

    如果你的 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.

    此示例按资源类型演示逻辑应用,因此,你的逻辑应用会显示在“逻辑应用”部分下。This example shows logic apps by resource type, so your logic apps appear under the Logic Apps section.

    从 Azure 门户打开部署的逻辑应用

    逻辑应用在逻辑应用设计器中打开后,可以在设计器的底部选择“代码视图”,以便查看逻辑应用的基础定义结构。After the logic app opens in Logic Apps Designer, at the bottom of the designer, you can select Code View so that you can review the underlying logic app definition structure. 若要为逻辑应用创建部署模板,请了解如何为该逻辑应用下载 Azure 资源管理器模板If you want to create a deployment template for the logic app, learn how to download an Azure Resource Manager template for that logic app. 详细了解资源管理器模板Learn more about Resource Manager templates.

从 Azure 下载Download from Azure

可以从 Azure 门户下载逻辑应用,并将其保存为 Azure 资源管理器模板。You can download logic apps from the Azure portal and save them as Azure Resource Manager templates. 然后,可以在本地使用 Visual Studio 编辑模板,并根据不同的部署环境自定义逻辑应用。You can then locally edit the templates with Visual Studio and customize logic apps for different deployment environments. 下载逻辑应用会在资源管理器模板中将这些逻辑应用的定义(也使用 JavaScript 对象表示法 (JSON))参数化Downloading logic apps automatically parameterizes their definitions inside Resource Manager templates, which also use JavaScript Object Notation (JSON).

  1. 在 Visual Studio 中打开 Cloud Explorer。In Visual Studio, open Cloud Explorer. 找到并选择要从 Azure 下载的逻辑应用。Find and select the logic app that you want to download from Azure.

  2. 在该应用的快捷菜单中,选择“使用逻辑应用编辑器打开”。On that app's shortcut menu, select Open with Logic App Editor.

    提示

    如果你的 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.

    逻辑应用设计器随即打开并显示该逻辑应用。The Logic App Designer opens and shows the logic app. 若要查看逻辑应用的基础定义和结构,请在设计器的底部选择“代码视图”。To review logic app's underlying definition and structure, at the bottom of the designer, select Code View.

  3. 在设计器工具栏上选择“下载”。On the designer toolbar, select Download.

    从 Azure 门户下载逻辑应用

  4. 当系统提示输入位置时,请浏览到该位置,并在资源管理器模板中以 JSON (.json) 文件格式保存逻辑应用的定义。When you're prompted for a location, browse to that location and save the Resource Manager template for the logic app definition in JSON (.json) file format.

    逻辑应用定义显示在资源管理器模板中的 resources 子节内。Your logic app definition appears in the resources subsection inside the Resource Manager template. 现在,可以使用 Visual Studio 来编辑逻辑应用定义和资源管理器模板。You can now edit the logic app definition and Resource Manager template with Visual Studio. 还可以将模板作为 Azure 资源组项目添加到 Visual Studio 解决方案中。You can also add the template as an Azure Resource Group project to a Visual Studio solution. 了解 Visual Studio 中逻辑应用的 Azure 资源组项目Learn about Azure Resource Group projects for logic apps in Visual Studio.

若要针对企业到企业 (B2B) 企业集成方案构建逻辑应用,可以将逻辑应用关联到以前创建的集成帐户,该帐户与逻辑应用存在于同一区域。To build logic apps for business-to-business (B2B) enterprise integration scenarios, you can link your logic app to a previously created integration account that exists in the same region as your logic app. 集成帐户包含 B2B 项目(例如贸易合作伙伴、协议、架构和映射),允许逻辑应用使用 B2B 连接器进行 XML 验证和平面文件编码或解码。An integration account contains B2B artifacts, such as trading partners, agreements, schemas, and maps, and lets your logic app use B2B connectors for XML validation and flat file encoding or decoding. 虽然可以使用 Azure 门户创建此关联,但也可以在满足先决条件后使用 Visual Studio,而逻辑应用则以 JSON (.json) 文件形式存在于 Azure 资源组项目中。Although you can create this link by using the Azure portal, you can also use Visual Studio after meeting the prerequisites, and your logic app exists as a JSON (.json) file inside an Azure Resource Group project. 了解 Visual Studio 中逻辑应用的 Azure 资源组项目Learn about Azure Resource Group projects for logic apps in Visual Studio.

  1. 在 Visual Studio 中,打开逻辑应用所在的 Azure 资源组项目。In Visual Studio, open the Azure Resource Group project that contains your logic app.

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

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

    提示

    如果 Visual Studio 2019 中没有此命令,请检查是否安装了 Visual Studio 和 Azure 逻辑应用工具扩展的最新更新。If you don't have this command in Visual Studio 2019, check that you have the latest updates to Visual Studio and the Azure Logic Apps Tools extension.

  3. 确保逻辑应用设计器有焦点,方法是:选择设计器的选项卡或图面,使“属性”窗口显示逻辑应用的“集成帐户”属性。Make sure that the Logic App Designer has focus by selecting the designer's tab or surface so that the Properties window shows the Integration Account property for your logic app.

    “属性”窗口 -“集成帐户”属性

    提示

    如果尚未打开“属性”窗口,请选择“视图”菜单中的“属性窗口”。If the Properties window isn't already open, from the View menu, select Properties Window. (键盘:按 F4)(Keyboard: Press F4)

  4. 打开“集成帐户”属性列表,选择要关联到逻辑应用的集成帐户,例如:Open the Integration Account property list, and select the integration account that you want to link to your logic app, for example:

    打开“集成帐户”属性列表

  5. 完成后,请记得保存 Visual Studio 解决方案。When you're done, remember to save your Visual Studio solution.

在 Visual Studio 中设置“集成帐户”属性并将逻辑应用另存为 Azure 资源管理器模板时,该模板也包含一个针对所选集成帐户的参数声明。When you set the Integration Account property in Visual Studio and save your logic app as an Azure Resource Manager template, that template also includes a parameter declaration for the selected integration account. 有关模板参数和逻辑应用的详细信息,请参阅概述:自动完成逻辑应用部署For more information about template parameters and logic apps, see Overview: Automate logic app deployment.

更改部署位置Change deployment location

在 Visual Studio 中,如果逻辑应用在用于自动执行部署的 Azure 资源组项目中作为 JSON (.json) 文件存在,则会为该逻辑应用设置一个位置类型和一个具体位置。In Visual Studio, if your logic app exists as a JSON (.json) file within an Azure Resource Group project that you use to automate deployment, that logic app is set to a location type and a specific location. 此位置可以是 Azure 区域,也可以是现有的集成服务环境 (ISE)。This location is either an Azure region or an existing integration service environment (ISE).

若要更改逻辑应用的位置类型或位置,必须使用逻辑应用设计器从解决方案资源管理器中打开逻辑应用的工作流定义 (.json) 文件。To change your logic app's location type or location, you have to open your logic app's workflow definition (.json) file from Solution Explorer by using the Logic App Designer. 不能使用 Cloud Explorer 更改这些属性。You can't change these properties by using Cloud Explorer.

  1. 在 Visual Studio 中,打开逻辑应用所在的 Azure 资源组项目。In Visual Studio, open the Azure Resource Group project that contains your logic app.

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

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

    提示

    如果 Visual Studio 2019 中没有此命令,请检查是否安装了 Visual Studio 和 Azure 逻辑应用工具扩展的最新更新。If you don't have this command in Visual Studio 2019, check that you have the latest updates to Visual Studio and the Azure Logic Apps Tools extension.

  3. 确保逻辑应用设计器有焦点,方法是:选择设计器的选项卡或图面,使“属性”窗口显示逻辑应用的“选择位置类型”和“位置”属性。 Make sure that the Logic App Designer has focus by selecting the designer's tab or surface so that the Properties window shows the Choose Location Type and Location properties for your logic app. 项目的位置类型设置为“区域”或“集成服务环境”。The project's location type is set to either Region or Integration Service Environment.

    属性窗口 -“选择位置类型”和“位置”属性

    提示

    如果尚未打开“属性”窗口,请选择“视图”菜单中的“属性窗口”。If the Properties window isn't already open, from the View menu, select Properties Window. (键盘:按 F4)(Keyboard: Press F4)

  4. 若要更改位置类型,请打开“选择位置类型”属性列表,然后选择所需的位置类型。To change the location type, open the Choose Location Type property list, and select the location type that you want.

    例如,如果位置类型为“集成服务环境”,则可以选择“区域”。For example, if the location type is Integration Service Environment, you can select Region.

    “选择位置类型”属性 - 更改位置类型

  5. 若要更改具体位置,请打开“位置”属性列表。To change the specific location, open the Location property list. 根据位置类型选择所需的位置,例如:Based on the location type, select the location that you want, for example:

    • 选择其他 Azure 区域:Select a different Azure region:

      打开“位置”属性列表,选择另一个 Azure 区域

    • 选择其他 ISE:Select a different ISE:

      打开“位置”属性列表,选择另一个 ISE

  6. 完成后,请记得保存 Visual Studio 解决方案。When you're done, remember to save your Visual Studio solution.

在 Visual Studio 中更改位置类型或位置并将逻辑应用另存为 Azure 资源管理器模板时,该模板还会包含针对该位置类型和位置的参数声明。When you change the location type or location in Visual Studio and save your logic app as an Azure Resource Manager template, that template also includes parameter declarations for that location type and location. 有关模板参数和逻辑应用的详细信息,请参阅概述:自动完成逻辑应用部署For more information about template parameters and logic apps, see Overview: Automate logic app deployment.

从 Azure 刷新Refresh from Azure

如果在 Azure 门户中编辑了逻辑应用并想要保存这些更改,请务必在 Visual Studio 中使用这些更改刷新该应用的版本。If you edit your logic app in the Azure portal and want to keep those changes, make sure that you refresh that app's version in Visual Studio with those changes.

  • 在 Visual Studio 中的逻辑应用设计器工具栏上,选择“刷新”。In Visual Studio, on the Logic App Designer toolbar, select Refresh.

    -或--or-

  • 在 Visual Studio Cloud Explorer 中打开逻辑应用的快捷菜单,选择“刷新”。In Visual Studio Cloud Explorer, open your logic app's shortcut menu, and select Refresh.

使用更新内容刷新逻辑应用

发布逻辑应用更新Publish logic app updates

准备好将逻辑应用更新从 Visual Studio 部署到 Azure 时,请在逻辑应用设计器工具栏上选择“发布”。When you're ready to deploy your logic app updates from Visual Studio to Azure, on the Logic App Designer toolbar, select Publish.

将更新的逻辑应用发布到 Azure 门户

手动运行逻辑应用Manually run your logic app

可以通过 Visual Studio 手动触发 Azure 中部署的逻辑应用。You can manually trigger a logic app deployed in Azure from Visual Studio. 在逻辑应用设计器工具栏上,选择“运行触发器”。On the Logic App Designer toolbar, select Run Trigger.

为逻辑应用手动运行触发器

查看运行历史记录Review run history

若要检查逻辑应用运行的状态和诊断问题,可以在 Visual Studio 中查看这些运行的详细信息,例如输入和输出。To check the status and diagnose problems with logic app runs, you can review the details, such as inputs and outputs, for those runs in Visual Studio.

  1. 在 Cloud Explorer 中打开逻辑应用的快捷菜单,选择“打开运行历史记录”。In Cloud Explorer, open your logic app's shortcut menu, and select Open run history.

    打开逻辑应用的运行历史记录

  2. 若要查看特定运行的详细信息,请双击该运行。To view the details for a specific run, double-click a run. 例如:For example:

    查看有关特定运行的信息

    提示

    若要按属性将表排序,请选择该属性的列标题。To sort the table by property, select the column header for that property.

  3. 展开要查看其输入和输出的步骤,例如:Expand the steps whose inputs and outputs you want to review, for example:

    查看每个步骤的输入和输出

禁用或启用逻辑应用Disable or enable logic app

如果不删除逻辑应用,可以在下一次满足触发条件时,阻止触发器激发。Without deleting your logic app, you can stop the trigger from firing the next time when the trigger condition is met. 禁用逻辑应用可以防止逻辑应用引擎创建和运行以后的逻辑应用工作流实例。Disabling your logic app prevents the Logic Apps engine from creating and running future workflow instances for your logic app. 在 Cloud Explorer 中打开逻辑应用的快捷菜单,选择“禁用”。In Cloud Explorer, open your logic app's shortcut menu, and select Disable.

在 Cloud Explorer 中禁用逻辑应用

备注

禁用逻辑应用后,任何新运行都不会实例化。When you disable a logic app, no new runs are instantiated. 所有正在进行的和挂起的运行将继续进行,直到完成,这可能要花费一些时间才能完成。All in-progress and pending runs will continue until they finish, which might take time to complete.

若要重新激活逻辑应用,请在 Cloud Explorer 中打开逻辑应用的快捷菜单,然后选择“启用”。To reactivate your logic app, in Cloud Explorer, open your logic app's shortcut menu, and select Enable.

在 Cloud Explorer 中启用逻辑应用

删除逻辑应用Delete your logic app

若要从 Azure 门户删除逻辑应用,请在 Cloud Explorer 中打开逻辑应用的快捷菜单,并选择“删除”。To delete your logic app from the Azure portal, in Cloud Explorer, open your logic app's shortcut menu, and select Delete.

从 Azure 门户删除逻辑应用

备注

删除逻辑应用后,任何新运行都不会实例化。When you delete a logic app, no new runs are instantiated. 所有正在进行和挂起的运行都将取消。All in-progress and pending runs are canceled. 如果有成千上万个运行,取消操作可能需要很长时间才能完成。If you have thousands of runs, cancellation might take significant time to complete.

备注

如果删除并重新创建了子逻辑应用,则必须重新保存父逻辑应用。If you delete and recreate a child logic app, you must resave the parent logic app. 重新创建的子应用将具有不同的元数据。The recreated child app will have different metadata. 如果在重新创建父逻辑应用的子逻辑应用后未重新保存父逻辑应用,则对子逻辑应用的调用将失败,并出现“未授权”错误。If you don't resave the parent logic app after recreating its child, your calls to the child logic app will fail with an error of "unauthorized." 此行为适用于父子逻辑应用,例如,那些使用集成帐户中的项目或调用 Azure 函数的逻辑应用。This behavior applies to parent-child logic apps, for example, those that use artifacts in integration accounts or call Azure functions.

故障排除Troubleshooting

在逻辑应用设计器中打开逻辑应用项目时,可能无法获取用于选择 Azure 订阅的选项。When you open your logic app project in the Logic Apps Designer, you might not get the option for selecting your Azure subscription. 而在逻辑应用打开时,Azure 订阅并非所要使用的订阅。Instead, your logic app opens with an Azure subscription that's not the one you want to use. 之所以发生此行为,原因在于当你打开逻辑应用的 .json 文件后,Visual Studio 将缓存首次选择的订阅,以供将来使用。This behavior happens because after you open a logic app's .json file, Visual Studio caches the first selected subscription for future use. 若要解决该问题,请尝试执行以下步骤之一:To resolve this problem, try one of these steps:

  • 重命名逻辑应用的 .json 文件。Rename the logic app's .json file. 订阅缓存依赖于该文件名。The subscription cache depends on the file name.

  • 若要删除解决方案中以前针对所有逻辑应用选择的订阅,请删除该解决方案目录中隐藏的 Visual Studio 设置文件夹 (.vs)。To remove previously selected subscriptions for all logic apps in your solution, delete the hidden Visual Studio settings folder (.vs) in your solution's directory. 此位置用于存储订阅信息。This location stores your subscription information.

后续步骤Next steps

本文已介绍如何使用 Visual Studio 管理部署的逻辑应用。In this article, you learned how to manage deployed logic apps with Visual Studio. 接下来,请了解如何自定义部署的逻辑应用定义:Next, learn about customizing logic app definitions for deployment: