微服务实践之使用 Visual Studio 2022 调试Dapr 应用程序

安装配置相关软件

安装 PowerShell 7 / Core

dotnet tool install --global PowerShell

安装 Visual Studio 扩展 Microsoft Child Process Debugging Power Tool 2022

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

这里save按钮要点,上面的保存按钮也要点

生成配置文件

<?xml version="1.0" encoding="utf-8"?>
<ChildProcessDebuggingSettings IsEnabled="true" xmlns="http://schemas.microsoft.com/vstudio/ChildProcessDebuggingSettings/2014">
  <DefaultRule Attach="false" />
  <Rule IsEnabled="true" ProcessName="dapr.exe" CommandLine="" EngineFilter="{3b476d35-a401-11d2-aad4-00c04f990171}" />
  <Rule IsEnabled="true" ProcessName="dotnet.exe" CommandLine="" EngineFilter="{3b476d35-a401-11d2-aad4-00c04f990171}" />
  <Rule IsEnabled="true" ProcessName="front.exe" CommandLine="" EngineFilter="{2e36f1d4-b23c-435d-ab41-18e608940038}" />
  <Rule IsEnabled="false" ProcessName="pwsh.exe" CommandLine="" EngineFilter="{3b476d35-a401-11d2-aad4-00c04f990171}" />
</ChildProcessDebuggingSettings>

修改launchSettings.json

{
  "profiles": {
    "http": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "dotnetRunMessages": true,
      "applicationUrl": "http://localhost:5000"
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Container (Dockerfile)": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
      "environmentVariables": {
        "ASPNETCORE_HTTP_PORTS": "8080"
      },
      "publishAllPorts": true
    },
    "Dapr-PWSH": {
      "commandName": "Executable",
      "executablePath": "pwsh",
      "commandLineArgs": "-Command \"dapr run --app-id front --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"
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:12247",
      "sslPort": 0
    }
  }
}

运行项目

切换到backend项目,运行下面命令,注意端口

dapr run --app-id backend --app-port 5001 dotnet run

开始调试front项目

访问:http://localhost:5000/swagger/index.html

正常进入调试

相关源码下载

相关文章

作者

吴晓阳 微信号:shiningrise

posted @ 2024-06-02 13:25  shiningrise  阅读(98)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css