This article is kind of an update to the previous one to describe the use of Comet for .NET Mobile by James Clancey to debug the .NET MAUI project and it’s available as an extension to VS Code.
This cute little extension automates the build and debug into a simple action rather than manually configuring it as described in the previous post.
To get started, launch VS Code, open Extensions (Shortcut: Ctrl+Shift+X), look for the Comet for .NET Mobile, and get it installed.
Create a new .NET MAUI project using .NET CLI command (
dotnet new maui) from your favorite terminal and open the MAUI project folder in VS Code (In case if you’ve just now landed into this blog, refer to my previous article on how to create a new MAUI project from template).
As it’s a new project, VS Code will offer the option to add default tasks for build and run, if so, kindly ignore it as this is going to get automated.
And it’s up to the user on whether to choose the Restore option upfront, as this will run anyway during the initial build and verify it on every consecutive build.
Now let’s configure the extension to automate the process:
- In the VS Code status bar, click on the Project Name and then select the target framework from the options provided (by design, .NET MAUI is multi-targeted from a single project)
- In this sample, have selected net6.0-android as my project target option
- Then click on the Select a Device option available next to the project name, this will load the list of configured emulators in the local machine (and physical devices too, if connected) as I’ve selected Android as my target framework
- I’ve two emulators configured in my machine, for API level 29 and 30, and have chosen Pixel 3a (API 30)
- Then need to add the Launch task, to do so, from Run menu, select Add Configuration … option
- As VS Code requires the PowerShell session to be in initialized state to present the next step. If no further action, look into the bottom right corner of status bar for the current state of the PowerShell session
- Once initialized, select Add Configuration … again to pick the Environment
- Now this will present the list of available Environments, select .NET Comet (Mobile), this will end up in creating the default launch.json file in the .vscode directory
- That’s it. No further change is required in the generated launch.json file
- Finally, Hit F5 or choose Start Debugging from the Run menu, this will build the project, attach to the debugger and launch the application in the selected emulator/device
It’s that simple. With very little effort, we’re able to debug the application, thanks to Clancey for making this possible.
For cross-platform users, a CLI-based .NET MAUI Item Templates is available to install from a NuGet package. And then can be invoked with dotnet new command. For more details, check out the GitHub repository.
For users on Windows installed with VS2019 and VS2022, a VS extension loaded with .NET MAUI Item Templates is available now. For further details, take a look at this article.
Stay connected as we continue to learn and share the experiences from this exciting journey of being a software developer …