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
Visual Studio for Mac version 8.6 or later. Select the option to install.NET Core. Installing Xamarin is optional for.NET Core development. For more information, see the following resources: Tutorial: Install Visual Studio for Mac. Supported macOS versions.NET Core versions supported by Visual Studio for Mac. Contact a MAC Admin. Report Technical Problems to the Service Desk @ 1-866-955-4357 (HELP) or e-mail: Service Desk Web Policies and Notices and Accessibility Statement. Install with Visual Studio for Mac. Visual Studio for Mac installs the.NET Core SDK when the.NET Core workload is selected. To get started with.NET Core development on macOS, see Install Visual Studio 2019 for Mac. For the latest release,.NET Core 3.1, you must use the Visual Studio for Mac 8.4. Install alongside Visual Studio Code.
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
Dot Net Machine Learning Library
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
Dot Net Machine
I have also created a video showcasing these steps in detail as well.