So you are new to Dapr and you are trying to understand how it works with you .NET Core application. You already tried launching your app with the Dapr CLI and then you find yourself wondering on how to debug the mix with Visual Studio Code.

Well, follow this simple steps and you’ll be ready:

Modify launch.json

Change the preLaunchTask so instead it calls a task named daprd-debug instead of build

Your launch.json file should look like this:

 1{
 2    // Use IntelliSense to learn about possible attributes.
 3    // Hover to view descriptions of existing attributes.
 4    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
 5    "version": "0.2.0",
 6    "configurations": [
 7        {
 8            "name": ".NET Core Launch (web)",
 9            "type": "coreclr",
10            "request": "launch",
11            "preLaunchTask": "daprd-debug",
12            "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/<your assembly name>.dll",
13            "args": [],
14            "cwd": "${workspaceFolder}",
15            "stopAtEntry": false,
16            "serverReadyAction": {
17                "action": "openExternally",
18                "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
19            },
20            "env": {
21                "ASPNETCORE_ENVIRONMENT": "Development"
22            },
23            "sourceFileMap": {
24                "/Views": "${workspaceFolder}/Views"
25            }
26        },
27        {
28            "name": ".NET Core Attach",
29            "type": "coreclr",
30            "request": "attach",
31            "processId": "${command:pickProcess}"
32        }
33    ]
34}

Modify tasks.json

A new task to tasks.json and name it daprd-debug or whatever name you choosed in te previous step.

Your tasks.json should look like this:

 1{
 2    "version": "2.0.0",
 3    "tasks": [
 4        // Ommited tasks.
 5        // ...
 6        {
 7            "label": "daprd-debug",
 8            "command": "daprd",
 9            "args": [
10                "-dapr-id",
11                "routing",
12                "-app-port",
13                "5000"
14            ],
15            "isBackground": true,
16            "problemMatcher": {
17                "pattern": [
18                    {
19                        "regexp": ".",
20                        "file": 1,
21                        "location": 2,
22                        "message": 3
23                    }
24                ],
25                "background": {
26                    "beginsPattern": "^.*starting Dapr Runtime.*",
27                    "endsPattern": "^.*waiting on port.*"
28                }
29            },
30            "dependsOn": "build"
31        }
32    ]
33}

Note: the new task depends on the build task.

Hit F5 and enjoy

Hit F5 and enjoy debugging your “Daprized” .NET Core application.

You can download a working sample from this repo.