使用 Visual Studio 2022 调试Dapr 应用程序

使用,visual,studio,调试,dapr,应用程序 · 浏览次数 : 1351

小编点评

## Using Dapr to create a multi-process program with Visual Studio debugging This document provides guidance on debugging a multi-process program created with Dapr and Orleans 7.0. **Prerequisites:** * Visual Studio 2022 with the Microsoft Child Process Debugging Power Tool plugin installed. * PowerShell 7/Core installed globally. * Dapr .NET SDK and associated projects. * A working example project: * **lab-dapr-with-famous-actors** (on GitHub) * **Dapr Orleans 7.0 Demo** (on GitHub) **Steps:** 1. **Configure project properties:** * Open the project in Visual Studio. * Right-click on the project in the Solution Explorer. * Go to Properties. * Select the "Build" tab. * Under "Advanced," click "Add" and select "New Item". * Select "Microsoft.Extensions.Configuration.Json.ConfigurationBuilder" and click "OK". * In the "appsettings.json" file, add the following configuration: ```json { "Dapr-PWSH": { "commandName": "Executable", "executablePath": "pwsh", "commandLineArgs": "-Command \\\"dapr run --app-id modDaprWithFamousActors --app-port 5000 --app-protocol grpc --log-level debug -- dotnet run --no-build\\\""", "workingDirectory": ".", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "nativeDebugging": true, "dotnetRunMessages": "true", "applicationUrl": "http://localhost:5000;https://localhost:5001" } } ``` 2. **Start debugging:** * Build and run the application. * The program will start in a new child window. * Visual Studio will automatically enable debugging for the child process. **Note:** * You cannot modify code in the running program while it is paused. * Using Dapr sidekick provides a more robust and flexible approach for managing child processes. **Additional resources:** * Github project examples: * **lab-dapr-with-famous-actors** * **Dapr Orleans 7.0 Demo** * Visual Studio debugging documentation: * Visual Studio Debug and Performance Tools By following these steps and referring to the provided resources, you should be able to effectively debug your multi-process program using Dapr and Visual Studio.

正文

使用Dapr 编写的是一个多进程的程序, 两个进程之间依赖于启动顺序来组成父子进程,使用Visual Studio 调试起来可能会比较困难,因为 Visual Studio 默认只会把你当前设置的启动项目的启动调试。 好在有Visual Studio 扩展(Microsoft Child Process Debugging Power Tool 插件)可以支持。这个思路来自 https://github.com/dapr/dotnet-sdk/issues/401#issuecomment-747563695

image

1、需要安装  PowerShell 7 / Core  (可使用命令行:dotnet tool install --global PowerShell)

2、需要安装 Visual Studio 扩展 Microsoft Child Process Debugging Power Tool 2022

安装插件后启动 Visual Studio,可以在 Debug -> Other Debugging Targets 中找到 Child Process Debugging Settings。

image

然后你可以按照下图的设置开启此项目的子进程调试:

image

我这里用的一个示例程序是 https://github.com/geffzhang/lab-dapr-with-famous-actors ,结合Dapr 和 Orleans 7.0 的一个Demo程序。

3、项目调试属性设置

image

保存后会自动生成文件 launchSettings.json

image

launchSettings.json 内容也可以通过文件直接修改,效果等同,文件如下:

"Dapr-PWSH": {
   "commandName": "Executable",
   "executablePath": "pwsh",
   "commandLineArgs": "-Command \"dapr run --app-id modDaprWithFamousActors --app-port 5000 --app-protocol grpc --log-level debug -- dotnet run --no-build\"",
   "workingDirectory": ".",
   "environmentVariables": {
     "ASPNETCORE_ENVIRONMENT": "Development"
   },
   "nativeDebugging": true,
   "dotnetRunMessages": "true",
   "applicationUrl": "http://localhost:5000;https://localhost:5001"
}

现在,你只需要开始调试你的程序,那么你程序中启动的新的子进程都将可以自动加入调试。

效果如下:

image

值得注意的是,只要启动了本机代码调试,就不能在程序暂停之后修改代码了(像平时调试纯托管代码那样)。

还有一个方案是采用Dapr sidekick,具体参考文章:  在非k8s 环境下 的应用 使用 Dapr Sidekick for .NET

与使用 Visual Studio 2022 调试Dapr 应用程序相似的内容:

使用 Visual Studio 2022 调试Dapr 应用程序

使用Dapr 编写的是一个多进程的程序, 两个进程之间依赖于启动顺序来组成父子进程,使用Visual Studio 调试起来可能会比较困难,因为 Visual Studio 默认只会把你当前设置的启动项目的启动调试。 好在有Visual Studio 扩展(Microsoft Child Proce

UOS 开启 VisualStudio 远程调试 .NET 应用之旅

本文记录的是在 Windows 系统里面,使用 VisualStudio 2022 远程调试运行在 UOS 里面 dotnet 应用的配置方法 本文写于 2024.03.19 如果你阅读本文的时间距离本文编写的时间过于长,那本文可能包含过期的知识 我将以我的 UOS 虚拟机作为例子告诉大家如何在 W

开发小技巧 - 合理使用Visual Studio 2022内置任务列表(TODO)

前言 在开发编码过程中经常会因为各种问题而打断自己的思绪和开发计划,可能会导致本来准备开发或者需要测试的功能到要上线的时候才想起来没有做完。这种情况相信很多同学都遇到过,咱们强大的Visual Studio内置了一个任务列表(TODO)能让我们当做待办清单功能使用,接下来我们快速了解一下。欢迎在评论

【Azure 云服务】为Azure云服务配置上自签名的SSL证书步骤

问题描述 在使用Azure Cloud Service(云服务),默认的情况下都是使用的 HTTP 服务,通过 Visual Studio 2022 创建的默认 Cloud Service项目中,在ServiceDefinition.csdef 服务定义文件中,值默认开启了HTTP 80的Endpo

利用选项卡提高Visual Studio 2022开发效率

设计器作为软件开发的必要工具,其效率的提高显得尤为重要。Visual Studio 2022作为一款功能强大的设计器,通过选项卡提高了工作效率,让开发者在使用过程中更加便捷。 在Visual Studio 2022中,选项卡功能的应用场景非常丰富。例如,当你在开发一个具有多个窗体的应用程序时,可以通

【译】Visual Studio Enterprise 中的代码覆盖率特性

通过使用代码覆盖率功能,您可以发现您的测试需要改进的地方,并使您的软件更加健壮和可靠。在这篇文章中,我们将介绍我们在 Visual Studio Enterprise 2022 中引入的 Code Coverage Results 窗口的新特性。

[转帖]vs调试运行程序出现:“由于找不到MSVCP140D.dll,无法继续执行代码 ”的解决方法

碎碎念 最近在使用Visual studio调试程序的时候,突然冒出了“由于找不到MSVCP140D.dll,无法继续执行代码。重新安装程序可能会解决次问题。”的错误。如下图所示。在网上尝试了很多别人的解决方案,都没有效果。 最后在不懈努力下终于可以正常运行了。 以下我尝试过的无效方案: 很多人说是

【Visual Studio 使用技巧分享】任务列表的使用

## 前言 **`Visual Studio`** 开发工具的熟练使用,能够潜在的提升我们工作效率,而且一些开发技巧的使用,会让我们的工作显得那么方便快捷。那么你知道VS中有哪些你不知道的使用小技巧呢?接下来,我们就来探索VS中的**“任务列表”**的使用。 任务列表是使用 `TODO` 、 `HA

C# 12 中的新增功能

新的 C# 12 功能在预览版中已经引入. 您可以使用最新的 Visual Studio 预览版或最新的 .NET 8 预览版 SDK 来尝试这些功能。以下是一些新引入的功能: 主构造函数 集合表达式 默认 Lambda 参数 任何类型的别名 内联数组 拦截器 使用nameof访问实例成员 主构造函

Visual Studio常用快捷键(附带免费PDF)

前言 对于开发者而言,熟悉快捷键的使用,能够起到事半功倍的作用,提高工作效率。以下是我整理的一份Visual Studio常用快捷键清单,希望能够帮助到你。 常用快捷方式 快捷键功能 Ctrl + K + C 注释选定内容 Ctrl + K + U 取消注释选定内容 Ctrl + K + D 代码格