Fork me on GitHub
Microsoft Child Process Debugging Power Tool 插件

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

 

使用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

posted on 2023-04-01 18:34  HackerVirus  阅读(351)  评论(1编辑  收藏  举报