Debug and Launch Dapr Applications in VSCode
This page shows you how to configure VSCode to run and debug multiple Dapr applications at same time.
Debug and launch Dapr applications in VSCode¶
We need to update VS code tasks.json
and launch.json
configuration files included in your workspace. Once completed you should be able to use the Run and Debug button on the activity bar within VS Code to launch all services to be able to debug them locally.
First we need to add a new launch configuration for the Backend Web API and Frontend Web App projects.
To accomplish this, open file launch.json
and add the two configurations shown below.
Note
Make sure you append the configurations below to the existing array instead of replacing what you have. This way you will preserve your existing configuration and simply add two new ones.
Looking for complete launch.json?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
Note
We have a preLaunchTask
and a postDebugTask
which we need to define right now. Those tasks are Dapr tasks.
The Dapr VSCode extension we have previously installed helps us to define those pre- and post-debug tasks.
To accomplish this, open the file tasks.json and click Ctrl+Shift+P, and type Dapr: Scaffold Dapr Tasks.
The Dapr VS Code extension will allow us to manage Dapr application and test it out in an easier way, the below image shows a full list of helper commands.
Now we will add 4 tasks, for each application, there will be a task to support the preLaunch
activity and the postDebug
activity (Terminate/Exit Dapr Sidecar process), so open file tasks.json and add the tasks below:
Curious to learn more about the tasks.json file above?
- The tasks with the label
backend-api-dapr-debug
will invoke thedaprd
task. This task is similar to calling dapr run from CLI. - We are setting the appPort, httpPort, and grpcPort properties (grpcPort is needed in future modules when we start using the state manager building block. If you didn't set it, you might face a similar issue)
- We are setting the “componentsPath” property. This is needed when start working with the state manager, pub/sub, etc.
- We are setting the dependsOn property, so this means this task will fire after the dependsOn tasks complete successfully. We need to add those dependsOn tasks.
- The tasks with the label
daprd-down-backend-api
will terminate the Dapr Sidecar process. This will be used for thepostDebug
activity in configuration.json. - For a complete list of available properties please check this link.
Next let's add the dependsOn tasks. Open tasks.json
and add the tasks below:
Looking for complete tasks.json?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
Lastly, we need to add a compound launch
property, so we launch and debug both applications together.
To accomplish this, open the file launch.json
again and add the below array after the configuration
array.
launch.json | |
---|---|