使用 Visual Studio 2022 调试Dapr 应用程序
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。
然后你可以按照下图的设置开启此项目的子进程调试:
我这里用的一个示例程序是 https://github.com/geffzhang/lab-dapr-with-famous-actors ,结合Dapr 和 Orleans 7.0 的一个Demo程序。
3、项目调试属性设置
保存后会自动生成文件 launchSettings.json
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"
}
现在,你只需要开始调试你的程序,那么你程序中启动的新的子进程都将可以自动加入调试。
效果如下:
值得注意的是,只要启动了本机代码调试,就不能在程序暂停之后修改代码了(像平时调试纯托管代码那样)。
还有一个方案是采用Dapr sidekick,具体参考文章: 在非k8s 环境下 的应用 使用 Dapr Sidekick for .NET

文章来源于互联网:使用 Visual Studio 2022 调试Dapr 应用程序