Using and setting Breakpoints in your code
In this section, we will learn how we can use the Visual Studio for Mac IDE to set Breakpoints in our PlanetaryApp
solution. We'll learn how to create conditional Breakpoints that can be used to perform a specific action.
Next, we will learn how we can utilize the Breakpoints Pad to view all Breakpoints that have been set in a solution. Finally, we will learn how we can use the Visual Studio for Mac debugger to step through our code and display the contents of variables in the Immediate window.
Setting a Breakpoint in your Planetary App solution
Breakpoints are a good way for you to pause execution at a particular point in the code contained in your project solution, so that you can debug your code or check the contents of a variable.
To set a breakpoint, simply follow the steps outlined here:
- Locate
MainPage.xaml.cs
in the .NET Standard (Shared Library) and ensure that theMainPage.xaml.cs
file is displayed in the code editor window - To set a Breakpoint, simply click to the left of the line number at the place in your code that you need to troubleshoot, as you can see in the following screenshot:

Setting a Breakpoint within the PlanetaryApp solution
As you can see from the preceding screenshot, whenever you set a breakpoint in your code, you will notice that the line will turn red, but this can be overridden in the Visual Studio for Mac Preferences
pane.
Using the Breakpoints Pad to view Breakpoints that have been set
Whenever you set Breakpoints in your code, rather than navigating through each of your individual code files in your project solution, you can quickly see all of these in one place by viewing them using the Breakpoints Pad.
To view all of the Breakpoints that have been set in your project, follow the steps outlined here:
- Ensure that the
MainPage.xaml.cs
file is displayed in the code editor window and choose theView|Debug Pads|Breakpoints
menu option:

Enable viewing of Breakpoints within your solution
- You will then see all
Breakpoints
that have been set in yourPlanetaryApp
project solution, including the ones that have been set in your subprojects, as can be seen in the following screenshot:

Displays all Breakpoints within your solution
As you can see in the preceding screenshot, you will see all Breakpoints that have been set in your .NET Standard (Shared Library) project, and even the ones that have been set in your PlanetaryApp.iOS
, PlanetaryApp.Android
and PlanetaryApp.UWP
subproject solutions.
Creating conditional Breakpoints to perform an action
In the previous section, we learned about Breakpoints and how you can set these in the code to pause execution whenever your code hits one of them. We also learned how to use the Breakpoints Pad to view all Breakpoints that have been set in your project solution.
Aside from setting Breakpoints, you can also set Conditional Breakpoints that will pause execution based upon whether a condition has been met, which we will covering in this section.
To create a conditional Breakpoint in your project, follow the steps outlined here:
- Ensure that the
MainPage.xaml.cs
file is displayed in the code editor window. - Next, right-click in the sidebar to bring up the pop-up menu and choose the
New Breakpoint…
menu option:

Creating a conditional breakpoint
This will then display the Create a Breakpoint
dialog where you can specify properties for certain actions, which can be seen in the following screenshot:

Specifying Breakpoint properties
As you can see in the preceding screenshot, you will see that you can specify either a Breakpoint Action
or When to Take Action
, as well as setting Additional Conditions
whenever a certain condition happens.