How can I use the .NET MAUI extension for VS Code to debug on my iOS/Android devices or simulators?
Asked Answered
P

3

9

I have installed the .NET MAUI extension for VS Code: https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-maui

In addition, the C# and C# Dev Kit extensions are installed.

But I don't see a menu in Visual Studio Code where I can choose a simulator or my iOS/Android devices.

How can I debug on my iOS/Android devices or simulators in Visual Studio Code? I use macOS Sonoma on my iMac.

UPDATE:

I cannot find the curly brackets symbol { } in the bottom right corner of Visual Studio Code. Why is the curly brackets symbol missing?

Visual Studio Code picture

Pettis answered 3/1, 2024 at 12:30 Comment(0)
M
8

In visual studio code, after creating the MAUI project, you can click on the curly brackets symbol { } in the bottom right corner of Visual Studio Code. Here, you can change your Startup Project, change your Debug Target to anything valid emulator device on your Mac, and pin either setting to the Visual Studio Code status bar.

For more details, you can refer to Choose your target device. enter image description here

Metagalaxy answered 4/1, 2024 at 8:39 Comment(4)
I cannot find the curly brackets symbol { } in the bottom right corner of Visual Studio Code. Why is the curly brackets symbol missing? I added a picture of VS code in my question.Pettis
Open a .cs or .xaml file in your project. The curly brackets doesn't appear when no file is open.Unfamiliar
Thanks. It works now on my iOS and Android device. I have not yet tested the simulators.Pettis
correct answer is Alexanders comment. thats a general information not an answer to OPs questionLignify
C
0

If you need to run your application by switching between devices from the terminal, unlike the curly brackets symbol { }, you can use the terminal codes below.

This method also provides the opportunity to switch between multiple .NET versions.

Please edit the .NET version and device information in the code according to your own environment.

for device name:

dotnet build -t:Run -f net8.0-android -p _DeviceName=:v2:udid:$(xcrun simctl list devices ‘pixel_5_api_34’ available | grep -om1 '[0-9A-F-]\{36\}')

for device id:

dotnet build -t:Run -f net7.0-ios -p:_DeviceName=:v2:udid=CAEF0A05-CAA1-4979-9898-03EBF6DXGHF5

WARNING: Make sure your devices are available! Otherwise, the devices will not wake up and the application will not start. Check your emulator devices with the terminal code below for the appropriate device list.

xcrun simctl list devices

NOTE: To work on a device that is not in the list (for no available device), run your device via Xcode, Android Studio or Visual Studio For MAC software and then run the application via VSCode.

Colloid answered 9/4, 2024 at 10:11 Comment(0)
P
0

A bit of a follow-up cause I encountered related issues.

In case you have the curly braces showing (MAUI Extension working properly), but no iOS emulators available in the dropdown menu of VS Code, make sure you have the supported Xcode version installed. Otherwise, given Xcode version may still be unsupported in .NET MAUI SDK release in use, so the VS Code does not recognize the emulators.

Also, initially MAUI compilation tries to target iOS version, and thus the emulator with the same release, for which support has been added in given Xcode version (i.e. Xcode 15.3 => iOS 17.4), so if you encounter build errors related to runtime version, verify this.

Phthisic answered 29/6, 2024 at 14:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.