-
Notifications
You must be signed in to change notification settings - Fork 554
[msbuild/dotnet] Add support for listing the devices and simulators available to run on. #24542
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dbb7375
[net11.0] [msbuild/dotnet] Add support for listing the devices and si…
rolfbjarne 0f6ace4
Improve comment.
rolfbjarne c7dd965
review
rolfbjarne d5dbb81
skip on x64
rolfbjarne bf3deae
Reapply #24468.
rolfbjarne d44eb55
Fix assertion messages.
rolfbjarne 02f0a34
Fix asynx pattern.
rolfbjarne 25e1081
Improve docs.
rolfbjarne de6ac20
Merge remote-tracking branch 'origin/main' into dev/rolf/backport-pr-…
rolfbjarne 3a65b14
Merge remote-tracking branch 'origin/main' into dev/rolf/backport-pr-…
rolfbjarne 0a2ab67
Fix build.
rolfbjarne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Target | ||
| Name="_PrepareRunDesktop" | ||
| BeforeTargets="ComputeRunArguments" | ||
| Condition="'$(_PlatformName)' == 'macOS' Or '$(_PlatformName)' == 'MacCatalyst'"> | ||
|
|
||
| <PropertyGroup Condition="'$(RunWithOpen)' != 'false'"> | ||
| <_OpenArguments Condition="'$(XamarinDebugMode)' != ''">$(_OpenArguments) --env __XAMARIN_DEBUG_MODE__=$(XamarinDebugMode)</_OpenArguments> | ||
| <_OpenArguments Condition="'$(XamarinDebugPort)' != ''">$(_OpenArguments) --env __XAMARIN_DEBUG_PORT__=$(XamarinDebugPort)</_OpenArguments> | ||
| <_OpenArguments Condition="'$(XamarinDebugHosts)' != ''">$(_OpenArguments) --env "__XAMARIN_DEBUG_HOSTS__=$(XamarinDebugHosts)"</_OpenArguments> | ||
| <_OpenArguments Condition="'$(XamarinDebugConnectTimeout)' != ''">$(_OpenArguments) --env __XAMARIN_DEBUG_CONNECT_TIMEOUT__=$(XamarinDebugConnectTimeout)</_OpenArguments> | ||
| <_OpenArguments Condition="'$(StandardOutputPath)' != ''">$(_OpenArguments) --stdout "$(StandardOutputPath)"</_OpenArguments> | ||
| <_OpenArguments Condition="'$(StandardErrorPath)' != ''">$(_OpenArguments) --stderr "$(StandardErrorPath)"</_OpenArguments> | ||
| <_OpenArguments Condition="'$(StandardInputPath)' != ''">$(_OpenArguments) --stdin "$(StandardInputPath)"</_OpenArguments> | ||
| <_OpenArgumentsPre Condition="'$(OpenNewInstance)' == 'true'">-n </_OpenArgumentsPre> | ||
| <_OpenArgumentsPre Condition="'$(OpenWaitForExit)' == 'true'">$(_OpenArgumentsPre) -W </_OpenArgumentsPre> | ||
| <_OpenArguments>$(_OpenArguments) $(RunEnvironment)</_OpenArguments> | ||
| <RunCommand>open</RunCommand> | ||
| <RunArguments>$(_OpenArgumentsPre) -a "$(TargetDir)/$(_AppBundleName).app" $(OpenArguments) $(_OpenArguments) --args</RunArguments> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup Condition="'$(RunWithOpen)' == 'false'"> | ||
| <RunCommand>$(TargetDir)/$(_AppBundleName).app/Contents/MacOS/$(_NativeExecutableName)</RunCommand> | ||
| <RunArguments /> | ||
| </PropertyGroup> | ||
| </Target> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
|
||
| <!-- Install & Run --> | ||
|
|
||
| <PropertyGroup> | ||
| <!-- We used to use '_MlaunchPath' as the property name, but we've made it public, so it's MlaunchPath now, but keep setting/supporting the underscored version for a while --> | ||
| <MlaunchPath Condition="'$(MlaunchPath)' == '' And '$(_MlaunchPath)' != ''">$(_MlaunchPath)</MlaunchPath> | ||
| <MlaunchPath Condition="'$(MlaunchPath)' == ''">$(_XamarinSdkRootDirectory)tools\bin\mlaunch</MlaunchPath> | ||
| <_MlaunchPath Condition="'$(_MlaunchPath)' == ''">$(MlaunchPath)</_MlaunchPath> | ||
| <!-- this is the path to mlaunch relative to the root of the .NET installation --> | ||
| <!-- We used to use '_RelativeMlaunchPath' as the property name, but we've made it public, so it's RelativeMlaunchPath now, but keep setting/supporting the underscored version for a while --> | ||
| <RelativeMlaunchPath Condition="'$(RelativeMlaunchPath)' == '' And '$(_RelativeMlaunchPath)' != ''">$(_RelativeMlaunchPath)</RelativeMlaunchPath> | ||
| <RelativeMlaunchPath Condition="'$(RelativeMlaunchPath)' == ''">$(XamarinRelativeSdkRootDirectory)tools\bin\mlaunch</RelativeMlaunchPath> | ||
| <_RelativeMlaunchPath Condition="'$(_RelativeMlaunchPath)' == ''">$(RelativeMlaunchPath)</_RelativeMlaunchPath> | ||
|
|
||
| <!-- Try to keep _DeviceName working for a while yet --> | ||
| <Device Condition="'$(Device)' == ''">$(_DeviceName)</Device> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
| </PropertyGroup> | ||
|
|
||
| <Target | ||
| Name="ShowRunHelp" | ||
| DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;_DetectAppManifest"> | ||
| <Error Condition="$([MSBuild]::IsOSPlatform('windows'))" Text="It's currently not supported to launch an app from the command line on Windows." /> | ||
| <Error Condition="!Exists('$(_AppBundleManifestPath)')" Text="The app must be built before showing how to launch it." /> | ||
|
|
||
| <GetMlaunchArguments | ||
| AppManifestPath="$(_AppBundleManifestPath)" | ||
| Help="true" | ||
| MlaunchPath="$(MlaunchPath)" | ||
| SdkDevPath="$(_SdkDevPath)" | ||
| SdkIsSimulator="$(_SdkIsSimulator)" | ||
| SdkVersion="$(_SdkVersion)" | ||
| SupportedOSPlatformVersion="$(SupportedOSPlatformVersion)" | ||
| TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" | ||
| > | ||
| </GetMlaunchArguments> | ||
|
|
||
| <!-- If invoked from 'dotnet run', don't actually run anything --> | ||
| <PropertyGroup> | ||
| <RunCommand>true</RunCommand> | ||
| <RunArguments /> | ||
| </PropertyGroup> | ||
| </Target> | ||
| <Target Name="_ShowRunHelpConditioned" Condition="'$(Help)' == 'true'" DependsOnTargets="ShowRunHelp" /> | ||
|
|
||
| <Target Name="ComputeMlaunchInstallArguments" DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;_DetectAppManifest;_ShowRunHelpConditioned;_ComputeMlaunchInstallArguments" /> | ||
| <Target Name="_ComputeMlaunchInstallArguments" Condition="'$(_SdkIsSimulator)' == 'false' And '$(Help)' != 'true'"> | ||
| <!-- Launching from the command line on windows hasn't been implemented: https://github.com/dotnet/macios/issues/16609 --> | ||
| <Error Condition="$([MSBuild]::IsOSPlatform('windows'))" Text="It's currently not supported to launch an app from the command line on Windows." /> | ||
| <Error Condition="!Exists('$(_AppBundleManifestPath)')" Text="The app must be built before the arguments to launch the app using mlaunch can be computed." /> | ||
|
|
||
| <GetMlaunchArguments | ||
| SessionId="$(BuildSessionId)" | ||
| AppManifestPath="$(_AppBundleManifestPath)" | ||
| DeviceName="$(Device)" | ||
| InstallApp="$(_AppBundlePath)" | ||
| MlaunchPath="$(MlaunchPath)" | ||
| SdkDevPath="$(_SdkDevPath)" | ||
| SdkIsSimulator="$(_SdkIsSimulator)" | ||
| SdkVersion="$(_SdkVersion)" | ||
| TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" | ||
| > | ||
| <Output TaskParameter="MlaunchArguments" PropertyName="MlaunchInstallArguments" /> | ||
| </GetMlaunchArguments> | ||
|
|
||
| <WriteLinesToFile | ||
| File="$(MlaunchInstallScript)" | ||
| Lines="$(MlaunchPath) $(MlaunchInstallArguments)" | ||
| Overwrite="true" | ||
| WriteOnlyWhenDifferent="true" | ||
| Condition="'$(MlaunchInstallScript)' != ''" | ||
| /> | ||
| </Target> | ||
|
|
||
| <Target Name="_InstallMobile" DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;ComputeMlaunchInstallArguments" Condition="'$(_SdkIsSimulator)' == 'false'"> | ||
| <Exec SessionId="$(BuildSessionId)" Command="'$(MlaunchPath)' $(MlaunchInstallArguments)" /> | ||
| </Target> | ||
|
|
||
| <Target Name="ComputeMlaunchRunArguments" DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;_DetectAppManifest;_ShowRunHelpConditioned;_ComputeMlaunchRunArguments" Condition="'$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'" /> | ||
|
|
||
| <Target Name="_ComputeMlaunchRunArguments" Condition="'$(Help)' != 'true'"> | ||
| <!-- Launching from the command line on windows hasn't been implemented: https://github.com/dotnet/macios/issues/16609 --> | ||
| <Error Condition="$([MSBuild]::IsOSPlatform('windows'))" Text="It's currently not supported to launch an app from the command line on Windows." /> | ||
| <Error Condition="!Exists('$(_AppBundleManifestPath)')" Text="The app must be built before the arguments to launch the app using mlaunch can be computed." /> | ||
|
|
||
| <PropertyGroup> | ||
| <!-- capture output by default --> | ||
| <_MlaunchCaptureOutput Condition="'$(_MlaunchCaptureOutput)' == ''">true</_MlaunchCaptureOutput> | ||
| <!-- wait for exit by default --> | ||
| <_MlaunchWaitForExit Condition="'$(_MlaunchWaitForExit)' == ''">true</_MlaunchWaitForExit> | ||
| <!-- don't set standard output/error path, mlaunch will by default write to stdout/stderr --> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_MODE__=$(XamarinDebugMode)" Condition="'$(XamarinDebugMode)' != ''" /> | ||
| <MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_PORT__=$(XamarinDebugPort)" Condition="'$(XamarinDebugPort)' != ''" /> | ||
| <MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_HOSTS__=$(XamarinDebugHosts.Replace(';', '%3B'))" Condition="'$(XamarinDebugHosts)' != ''" /> | ||
| <MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_CONNECT_TIMEOUT__=$(XamarinDebugConnectTimeout)" Condition="'$(XamarinDebugConnectTimeout)' != ''" /> | ||
| <!-- It's not possible to set an item group from the command line, so add support for setting a property (with semi-colon separated items) that we'll include into the item group --> | ||
| <MlaunchAdditionalArguments Include="$(MlaunchAdditionalArgumentsProperty)" Condition="'$(MlaunchAdditionalArgumentsProperty)' != ''" /> | ||
| </ItemGroup> | ||
| <GetMlaunchArguments | ||
| SessionId="$(BuildSessionId)" | ||
| AdditionalArguments="@(MlaunchAdditionalArguments)" | ||
| AppManifestPath="$(_AppBundleManifestPath)" | ||
| CaptureOutput="$(_MlaunchCaptureOutput)" | ||
| DeviceName="$(Device)" | ||
| EnvironmentVariables="@(MlaunchEnvironmentVariables)" | ||
| LaunchApp="$(_AppBundlePath)" | ||
| MlaunchPath="$(MlaunchPath)" | ||
| SdkIsSimulator="$(_SdkIsSimulator)" | ||
| SdkDevPath="$(_SdkDevPath)" | ||
| SdkVersion="$(_SdkVersion)" | ||
| StandardErrorPath="$(_MlaunchStandardErrorPath)" | ||
| StandardOutputPath="$(_MlaunchStandardOutputPath)" | ||
| TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" | ||
| WaitForExit="$(_MlaunchWaitForExit)" | ||
| > | ||
| <Output TaskParameter="MlaunchArguments" PropertyName="MlaunchRunArguments" /> | ||
| </GetMlaunchArguments> | ||
|
|
||
| <WriteLinesToFile | ||
| File="$(MlaunchRunScript)" | ||
| Lines="$(MlaunchPath) $(MlaunchRunArguments)" | ||
| Overwrite="true" | ||
| WriteOnlyWhenDifferent="true" | ||
| Condition="'$(MlaunchRunScript)' != ''" | ||
| /> | ||
|
|
||
| <PropertyGroup> | ||
| <RunCommand>$(MlaunchPath)</RunCommand> | ||
| <RunArguments>$(MlaunchRunArguments) -- </RunArguments> | ||
| </PropertyGroup> | ||
| </Target> | ||
|
|
||
| <!-- This is only needed for mobile platforms, RunCommand and RunArguments are defined for macOS in Microsoft.macOS.Sdk.targets. --> | ||
| <Target | ||
| Name="_PrepareRunMobile" | ||
| BeforeTargets="ComputeRunArguments" | ||
| DependsOnTargets="_InstallMobile;ComputeMlaunchRunArguments" | ||
| Condition="'$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'"> | ||
| </Target> | ||
|
|
||
| <!-- | ||
| *********************************************************************************************** | ||
| ComputeAvailableDevices | ||
| Target that queries available devices and simulators. | ||
| This target is called by 'dotnet run' to support device selection. | ||
| Returns @(Devices) items that always has these metadata: Description, Type, OSVersion, UDID, RuntimeIdentifier | ||
| (but others might be present too, for debug purposes, depending on whether it's a simulator or a device) | ||
| See: https://github.com/dotnet/sdk/blob/2b9fc02a265c735f2132e4e3626e94962e48bdf5/documentation/specs/dotnet-run-for-maui.md | ||
| *********************************************************************************************** | ||
| --> | ||
| <Target Name="ComputeAvailableDevices" | ||
| DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;" | ||
| Condition="'$(_PlatformName)' == 'iOS' Or '$(_PlatformName)' == 'tvOS'" | ||
| Returns="@(Devices)"> | ||
| <PropertyGroup> | ||
| <_FilterDevicesToRuntimeIdentifier Condition="'$(_XamarinUsingDefaultRuntimeIdentifier)' != 'true'">$(RuntimeIdentifier)</_FilterDevicesToRuntimeIdentifier> | ||
| </PropertyGroup> | ||
| <GetAvailableDevices | ||
| Condition="'$(IsMacEnabled)' == 'true'" | ||
| SessionId="$(BuildSessionId)" | ||
| AppBundleManifestPath="$(_AppBundleManifestPath)" | ||
| RuntimeIdentifier="$(_FilterDevicesToRuntimeIdentifier)" | ||
| SdkDevPath="$(_SdkDevPath)" | ||
| TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" | ||
| Verbose="$(Verbose)" | ||
| > | ||
| <Output TaskParameter="Devices" ItemName="Devices" /> | ||
| <Output TaskParameter="DiscardedDevices" ItemName="DiscardedDevices" /> | ||
| </GetAvailableDevices> | ||
| </Target> | ||
|
|
||
| </Project> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.