Skip to content

_EnsureDeviceBooted target does not fire during dotnet run deploy step #10965

@rmarinho

Description

@rmarinho

Description

When running dotnet run --project <android-project>, the _EnsureDeviceBooted target never executes before _DeployApk, causing deployment to fail with adb: no devices/emulators found when the selected device is an unbooted AVD emulator.

Root Cause

_EnsureDeviceBooted is defined with BeforeTargets="_GetPrimaryCpuAbi;_DeployApk;_DeployAppBundle". However, the .NET SDK's dotnet run command invokes the DeployToDevice target via ProjectInstance.Build() in-process (in RunCommandSelector.TryDeployToDevice()), and the BeforeTargets hooks are not triggered in that code path.

When the same target is invoked via a separate MSBuild process (msbuild -t:DeployToDevice -p:Device=<avd>), _EnsureDeviceBooted fires correctly, boots the emulator, and deployment succeeds.

Steps to Reproduce

  1. Have a single AVD emulator available (not running): emulator -list-avdsMAUI_Emulator_API_36
  2. Run: dotnet run --project <android-app>.csproj
  3. The SDK auto-selects the emulator and passes Device=MAUI_Emulator_API_36
  4. Build succeeds, but _DeployApk runs adb install without -s flag → fails with "no devices/emulators found"
  5. _EnsureDeviceBooted never appears in diagnostic logs

Expected Behavior

_EnsureDeviceBooted should boot the emulator before _DeployApk runs, resolving AdbTarget to "-s emulator-5554".

Proposed Fix

Add _EnsureDeviceBooted to DeployToDeviceDependsOnTargets in Microsoft.Android.Sdk.BuildOrder.targets (before _DeployApk), so it runs via DependsOnTargets rather than relying solely on BeforeTargets. Keep the existing BeforeTargets for _GetPrimaryCpuAbi (commercial builds).

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageIssues that need to be assigned.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions