In my previous blog post I have written about running your first dotnet app in a MAC machine. In this post, we will see how we can debug the same app using VSCode Editor. To start debugging your app, we need to have two files configured in the project
- Launch.json – maintains the debugging session’s launching configurations and other details
- Tasks.json – maintains the information about the tasks for the current project. The tasks could be anything from build, test, restore (for this dotnet app). We will see what other types of tasks can be created in detail later.
Step 1 : Create launch.json
In VS Code Editor, click on Debug button on the left side, and then Click on Settings button to create the launch.json file. Refer screen shot below:
Once the launch.json is created, you should see 3 different run configurations
- .Net core launch (console) – To start debugging the console app
- .Net core launch (web) – To start debugging the web app (asp.net core app)
- .Net core attach – Attaching the codebase to already running core app.
For brevity, I have taken only the first configuration which is to debug the console app.
“name”: “.NET Core Launch (console)”,
“type”: “coreclr”,
“request”: “launch”,
“preLaunchTask”: “build”,
“program”: “${workspaceRoot}/bin/Debug/netcoreapp1.0/dotnetDemoApp.dll”,
“args”: [],
“cwd”: “${workspaceRoot}”,
“stopAtEntry”: false
Below are some of the notable configuration entries we need to be aware of
preLaunchTask – this is set to the dotnet build task, which will precede the debugging session (this task will be created in tasks.json file)
program – the name of the program which needs to be debugged, in this case the full path of the current app. The finished launch.json will look like the one in the below screenshot
Now that launch.json is ready, next up is to create the tasks.json which will specify the build task (marked as preLaunchTask) in the launch.json file
Step 2: Create tasks.json
Click on the Play button left to the configurations drop down, and VS Code will throw a dialog to create the tasks.json file. The created file will look like the one below
Step 3 : Start debugging
Before starting debugging, make sure to add some breakpoints by clicking to the left of the line number and press Play button. You should start seeing the app getting launched and hitting the breakpoint. Refer screenshot below
Step 4: Debug more and write more
I have also created a video showcasing these steps in detail as well.