Skip to content

[dotnet run] ComputeAvailableDevices lists available emulators and auto-boot on deploy#10826

Draft
jonathanpeppers wants to merge 7 commits intomainfrom
dev/peppers/dotnet-run-launch
Draft

[dotnet run] ComputeAvailableDevices lists available emulators and auto-boot on deploy#10826
jonathanpeppers wants to merge 7 commits intomainfrom
dev/peppers/dotnet-run-launch

Conversation

@jonathanpeppers
Copy link
Member

Fixes: #10702

Context: IDEs (Visual Studio) handle emulator discovery and boot through the commercial android-platform-support repo. The key files are:

This PR provides a simpler MSBuild-only equivalent for dotnet run:

  • emulator -list-avds instead of filesystem watchers for AVD discovery
  • BootAndroidEmulator task instead of IDE-level process management
  • Display names derived from AVD folder names (underscores to spaces, title case) instead of parsing config.ini/avd.ini.displayname

Changes:

  • Extended GetAvailableAndroidDevices task to query emulator -list-avds and merge not-running emulators with adb devices output, sorted with online devices first, then offline emulators alphabetically.

  • Added EmulatorToolPath/EmulatorToolExe/AdbToolExe properties to _ResolveMonoAndroidSdks (ported AdbToolPath from CreateProperty).

  • Added BootAndroidEmulator task to boot a not-running AVD and wait for it to come online, resolving the ADB serial (e.g. emulator-5554).

  • Added _EnsureDeviceBooted target (BeforeTargets=_GetPrimaryCpuAbi;_DeployApk;_DeployAppBundle) so selecting a not-running emulator auto-boots it before deploy.

  • Updated Resources.Designer.cs by opening the resx in Visual Studio to regenerate it (the designer file was stale) and discarding whitespace changes.

…auto-boot on deploy

Fixes: #10702

Context: IDEs (Visual Studio) handle emulator discovery and boot through the
commercial `android-platform-support` repo. The key files are:

- `src/Mono.AndroidTools/Internal/AvdWatcher.cs`:
  https://devdiv.visualstudio.com/DevDiv/_git/android-platform-support?path=/src/Mono.AndroidTools/Internal/AvdWatcher.cs
  Uses `FileSystemWatcher` on `~/.android/avd/*.ini` to discover AVDs (no
  `emulator -list-avds` call). Parses `.ini` files to load AVD metadata.

- `src/Mono.AndroidTools/AndroidVirtualDeviceManager.cs`:
  https://devdiv.visualstudio.com/DevDiv/_git/android-platform-support?path=/src/Mono.AndroidTools/AndroidVirtualDeviceManager.cs
  Manages the full AVD lifecycle. `GetRunArguments()` constructs emulator
  launch arguments (`-avd`, `-netfast`, `-no-snapshot-load`, etc.).

- `src/Mono.AndroidTools/AndroidVirtualDevice.cs`:
  https://devdiv.visualstudio.com/DevDiv/_git/android-platform-support?path=/src/Mono.AndroidTools/AndroidVirtualDevice.cs
  Loads AVD config from `.ini` files, reads `avd.ini.displayname` for
  friendly names, parses API level from target strings.

- `src/Mono.AndroidTools/AndroidDeviceManager.cs`:
  https://devdiv.visualstudio.com/DevDiv/_git/android-platform-support?path=/src/Mono.AndroidTools/AndroidDeviceManager.cs
  Tracks connected devices via `adb track-devices` (persistent connection).

This PR provides a simpler MSBuild-only equivalent for `dotnet run`:
- `emulator -list-avds` instead of filesystem watchers for AVD discovery
- `BootAndroidEmulator` task instead of IDE-level process management
- Display names derived from AVD folder names (underscores to spaces, title case)
  instead of parsing `config.ini`/`avd.ini.displayname`

Changes:

- Extended `GetAvailableAndroidDevices` task to query `emulator -list-avds`
  and merge not-running emulators with `adb devices` output, sorted with
  online devices first, then offline emulators alphabetically.

- Added `EmulatorToolPath`/`EmulatorToolExe`/`AdbToolExe` properties to
  `_ResolveMonoAndroidSdks` (ported `AdbToolPath` from `CreateProperty`).

- Added `BootAndroidEmulator` task to boot a not-running AVD and wait for it
  to come online, resolving the ADB serial (e.g. `emulator-5554`).

- Added `_EnsureDeviceBooted` target
  (`BeforeTargets=_GetPrimaryCpuAbi;_DeployApk;_DeployAppBundle`) so
  selecting a not-running emulator auto-boots it before deploy.

- Updated `Resources.Designer.cs` by opening the resx in Visual Studio to
  regenerate it (the designer file was stale) and discarding whitespace changes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables dotnet run to discover and auto-boot Android emulators, addressing issue #10702. The implementation adds emulator discovery via emulator -list-avds and automatic emulator booting when deploying to a not-running emulator.

Changes:

  • Extended GetAvailableAndroidDevices to query available emulators and merge them with running devices
  • Added BootAndroidEmulator task to boot emulators and wait for them to come online
  • Updated MSBuild properties and targets to support emulator tool paths and auto-boot integration

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Tasks/GetAvailableAndroidDevices.cs Added emulator listing via emulator -list-avds, AVD name retrieval, and device/emulator merging logic with sorting
src/Xamarin.Android.Build.Tasks/Tasks/BootAndroidEmulator.cs New task to boot emulators, detect running status, wait for full boot completion, and resolve ADB serials
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/GetAvailableAndroidDevicesTests.cs Added comprehensive tests for emulator merging, duplicate detection, sorting, and case-insensitive matching
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Application.targets Added BootAndroidEmulator task declaration, _EnsureDeviceBooted target to auto-boot emulators before deployment, and emulator tool properties to ComputeAvailableDevices
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets Defined AdbToolPath, AdbToolExe, EmulatorToolPath, and EmulatorToolExe properties with OS-specific defaults
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx Added error messages XA0143-XA0145 for emulator boot failures and timeouts
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs Regenerated designer file to add new error code properties and update tool version to 18.0.0.0
.github/copilot-instructions.md Added guideline to avoid #region/#endregion in C# code
Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Language not supported

Copy link
Member Author

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@jonathanpeppers jonathanpeppers marked this pull request as draft February 18, 2026 14:44
@jonathanpeppers jonathanpeppers added the copilot `copilot-cli` or other AIs were used to author this label Feb 18, 2026
…ndroidSdkDirectory

_EnsureDeviceBooted cannot use DependsOnTargets='_ResolveMonoAndroidSdks' because
in commercial builds _GetPrimaryCpuAbi is in _ResolveMonoAndroidSdksDependsOn,
creating a cycle. Instead, restore BeforeTargets='_GetPrimaryCpuAbi' so AdbTarget
is correct, and let BootAndroidEmulator compute tool paths from AndroidSdkDirectory
(which is available because _ResolveSdks runs earlier in the dependency chain).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot `copilot-cli` or other AIs were used to author this

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'dotnet run' should display emulators that are not running, and be able to boot them

1 participant

Comments