-
Notifications
You must be signed in to change notification settings - Fork 564
[xabt] implement $(Device) and ComputeAvailableDevices MSBuild target
#10576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…rget Context: https://github.com/dotnet/sdk/blob/2b9fc02a265c735f2132e4e3626e94962e48bdf5/documentation/specs/dotnet-run-for-maui.md This implements the first couple of steps to support new `dotnet run` behavior in .NET 11. * `$(Device)` MSBuild property to specify target device (passed from `dotnet run --device <id>`). This will simply set `$(AdbTarget)` for now. * `ComputeAvailableDevices` MSBuild target to get the list of connected Android devices/emulators using `adb devices` command: Target ComputeAvailableDevices 55 ms Using "GetAvailableAndroidDevices" task from assembly "D:\src\xamarin-android\bin\Debug\lib\packs\Microsoft.Android.Sdk.Windows\36.1.99\targets\..\tools\Xamarin.Android.Build.Tasks.dll". Task GetAvailableAndroidDevices 55 ms Assembly = D:\src\xamarin-android\bin\Debug\lib\packs\Microsoft.Android.Sdk.Windows\36.1.99\tools\Xamarin.Android.Build.Tasks.dll Parameters 16:47:08.2643378 C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe devices -l 16:47:08.2867570 List of devices attached 16:47:08.2867734 0A041FDD400327 device product:redfin model:Pixel_5 device:redfin transport_id:2 16:47:08.2867765 emulator-5554 device product:sdk_gphone64_x86_64 model:sdk_gphone64_x86_64 device:emu64xa transport_id:1 16:47:08.2920363 Running process: C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 emu avd name 16:47:08.3172534 pixel_7_-_api_36 16:47:08.3172747 OK 16:47:08.3183905 Running process: exit code == 0 16:47:08.3185099 Found 2 Android device(s)/emulator(s) OutputItems TargetOutputs 0A041FDD400327 Status = Online Type = Device Device = redfin TransportId = 2 Description = Pixel 5 Product = redfin Model = Pixel_5 emulator-5554 Status = Online Type = Emulator Device = emu64xa TransportId = 1 Description = pixel 7 - api 36 Product = sdk_gphone64_x86_64 Model = sdk_gphone64_x86_64 Some of the extra MSBuild item metadata was completely optional, I just left anything that `adb devices -l` reports to be in here. Added unit tests for `GetAvailableAndroidDevices` task, that mostly test input/output parsing without actually running `adb`.
baronfel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! I'm pretty happy with how straightforward this hook-up is.
| <Target Name="ComputeAvailableDevices" | ||
| DependsOnTargets="_ResolveMonoAndroidSdks" | ||
| Returns="@(Devices)"> | ||
| <GetAvailableAndroidDevices | ||
| ToolExe="$(AdbToolExe)" | ||
| ToolPath="$(AdbToolPath)"> | ||
| <Output TaskParameter="Devices" ItemName="Devices" /> | ||
| </GetAvailableAndroidDevices> | ||
| </Target> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any possible world where there's some way to do input/output tracking here for incrementality purposes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has to query each time because you could click the X on the emulator, unplug the device, etc.
It was taking 55ms on my machine, but we can see if there are different adb commands that are faster in the future. I was also thinking about reading files on disk like %userprofile%\.android\avd\pixel_7_-_api_36.ini that could be faster than launching a new process.
rolfbjarne
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I'll look into creating a PR for macios next week.
…vailable to run on. This consists of two parts: * Add an MSBuild target that lists all the available devices (`ComputeAvailableDevices`), by returning them in a `$(Devices)` item group. * Add support for the `$(Device)` property to specify the device or simulator to use. Regarding the device list, we'll filter the returned list by: * Platform (don't return an Apple TV simulator for an iOS app). * Minimum OS version (not return an iOS 18.0 device when the app's minimum OS version is 26.0). * Only devices that are actually available, as reported by `devicectl` or `simctl`. References: * dotnet/android#10576 * https://github.com/dotnet/sdk/blob/2b9fc02a265c735f2132e4e3626e94962e48bdf5/documentation/specs/dotnet-run-for-maui.md Fixes #23995.
Context: https://github.com/dotnet/sdk/blob/2b9fc02a265c735f2132e4e3626e94962e48bdf5/documentation/specs/dotnet-run-for-maui.md
This implements the first couple of steps to support new
dotnet runbehavior in .NET 11.$(Device)MSBuild property to specify target device (passed fromdotnet run --device <id>). This will simply set$(AdbTarget)for now.ComputeAvailableDevicesMSBuild target to get the list of connected Android devices/emulators usingadb devicescommand:Some of the extra MSBuild item metadata was completely optional, I just left anything that
adb devices -lreports to be in here.Added unit tests for
GetAvailableAndroidDevicestask, that mostly test input/output parsing without actually runningadb.