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
- Have a single AVD emulator available (not running):
emulator -list-avds → MAUI_Emulator_API_36
- Run:
dotnet run --project <android-app>.csproj
- The SDK auto-selects the emulator and passes
Device=MAUI_Emulator_API_36
- Build succeeds, but
_DeployApk runs adb install without -s flag → fails with "no devices/emulators found"
_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).
Description
When running
dotnet run --project <android-project>, the_EnsureDeviceBootedtarget never executes before_DeployApk, causing deployment to fail withadb: no devices/emulators foundwhen the selected device is an unbooted AVD emulator.Root Cause
_EnsureDeviceBootedis defined withBeforeTargets="_GetPrimaryCpuAbi;_DeployApk;_DeployAppBundle". However, the .NET SDK'sdotnet runcommand invokes theDeployToDevicetarget viaProjectInstance.Build()in-process (inRunCommandSelector.TryDeployToDevice()), and theBeforeTargetshooks are not triggered in that code path.When the same target is invoked via a separate MSBuild process (
msbuild -t:DeployToDevice -p:Device=<avd>),_EnsureDeviceBootedfires correctly, boots the emulator, and deployment succeeds.Steps to Reproduce
emulator -list-avds→MAUI_Emulator_API_36dotnet run --project <android-app>.csprojDevice=MAUI_Emulator_API_36_DeployApkrunsadb installwithout-sflag → fails with "no devices/emulators found"_EnsureDeviceBootednever appears in diagnostic logsExpected Behavior
_EnsureDeviceBootedshould boot the emulator before_DeployApkruns, resolvingAdbTargetto"-s emulator-5554".Proposed Fix
Add
_EnsureDeviceBootedtoDeployToDeviceDependsOnTargetsinMicrosoft.Android.Sdk.BuildOrder.targets(before_DeployApk), so it runs viaDependsOnTargetsrather than relying solely onBeforeTargets. Keep the existingBeforeTargetsfor_GetPrimaryCpuAbi(commercial builds).