|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 3 | + |
| 4 | + <!-- Install & Run --> |
| 5 | + |
| 6 | + <PropertyGroup> |
| 7 | + <!-- 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 --> |
| 8 | + <MlaunchPath Condition="'$(MlaunchPath)' == '' And '$(_MlaunchPath)' != ''">$(_MlaunchPath)</MlaunchPath> |
| 9 | + <MlaunchPath Condition="'$(MlaunchPath)' == ''">$(_XamarinSdkRootDirectory)tools\bin\mlaunch</MlaunchPath> |
| 10 | + <_MlaunchPath Condition="'$(_MlaunchPath)' == ''">$(MlaunchPath)</_MlaunchPath> |
| 11 | + <!-- this is the path to mlaunch relative to the root of the .NET installation --> |
| 12 | + <!-- 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 --> |
| 13 | + <RelativeMlaunchPath Condition="'$(RelativeMlaunchPath)' == '' And '$(_RelativeMlaunchPath)' != ''">$(_RelativeMlaunchPath)</RelativeMlaunchPath> |
| 14 | + <RelativeMlaunchPath Condition="'$(RelativeMlaunchPath)' == ''">$(XamarinRelativeSdkRootDirectory)tools\bin\mlaunch</RelativeMlaunchPath> |
| 15 | + <_RelativeMlaunchPath Condition="'$(_RelativeMlaunchPath)' == ''">$(RelativeMlaunchPath)</_RelativeMlaunchPath> |
| 16 | + |
| 17 | + <!-- Try to keep _DeviceName working for a while yet --> |
| 18 | + <Device Condition="'$(Device)' == ''">$(_DeviceName)</Device> |
| 19 | + </PropertyGroup> |
| 20 | + |
| 21 | + <Target |
| 22 | + Name="ShowRunHelp" |
| 23 | + DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;_DetectAppManifest"> |
| 24 | + <Error Condition="$([MSBuild]::IsOSPlatform('windows'))" Text="It's currently not supported to launch an app from the command line on Windows." /> |
| 25 | + <Error Condition="!Exists('$(_AppBundleManifestPath)')" Text="The app must be built before showing how to launch it." /> |
| 26 | + |
| 27 | + <GetMlaunchArguments |
| 28 | + AppManifestPath="$(_AppBundleManifestPath)" |
| 29 | + Help="true" |
| 30 | + MlaunchPath="$(MlaunchPath)" |
| 31 | + SdkDevPath="$(_SdkDevPath)" |
| 32 | + SdkIsSimulator="$(_SdkIsSimulator)" |
| 33 | + SdkVersion="$(_SdkVersion)" |
| 34 | + SupportedOSPlatformVersion="$(SupportedOSPlatformVersion)" |
| 35 | + TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" |
| 36 | + > |
| 37 | + </GetMlaunchArguments> |
| 38 | + |
| 39 | + <!-- If invoked from 'dotnet run', don't actually run anything --> |
| 40 | + <PropertyGroup> |
| 41 | + <RunCommand>true</RunCommand> |
| 42 | + <RunArguments /> |
| 43 | + </PropertyGroup> |
| 44 | + </Target> |
| 45 | + <Target Name="_ShowRunHelpConditioned" Condition="'$(Help)' == 'true'" DependsOnTargets="ShowRunHelp" /> |
| 46 | + |
| 47 | + <Target Name="ComputeMlaunchInstallArguments" DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;_DetectAppManifest;_ShowRunHelpConditioned;_ComputeMlaunchInstallArguments" /> |
| 48 | + <Target Name="_ComputeMlaunchInstallArguments" Condition="'$(_SdkIsSimulator)' == 'false' And '$(Help)' != 'true'"> |
| 49 | + <!-- Launching from the command line on windows hasn't been implemented: https://github.com/dotnet/macios/issues/16609 --> |
| 50 | + <Error Condition="$([MSBuild]::IsOSPlatform('windows'))" Text="It's currently not supported to launch an app from the command line on Windows." /> |
| 51 | + <Error Condition="!Exists('$(_AppBundleManifestPath)')" Text="The app must be built before the arguments to launch the app using mlaunch can be computed." /> |
| 52 | + |
| 53 | + <GetMlaunchArguments |
| 54 | + SessionId="$(BuildSessionId)" |
| 55 | + AppManifestPath="$(_AppBundleManifestPath)" |
| 56 | + DeviceName="$(Device)" |
| 57 | + InstallApp="$(_AppBundlePath)" |
| 58 | + MlaunchPath="$(MlaunchPath)" |
| 59 | + SdkDevPath="$(_SdkDevPath)" |
| 60 | + SdkIsSimulator="$(_SdkIsSimulator)" |
| 61 | + SdkVersion="$(_SdkVersion)" |
| 62 | + TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" |
| 63 | + > |
| 64 | + <Output TaskParameter="MlaunchArguments" PropertyName="MlaunchInstallArguments" /> |
| 65 | + </GetMlaunchArguments> |
| 66 | + |
| 67 | + <WriteLinesToFile |
| 68 | + File="$(MlaunchInstallScript)" |
| 69 | + Lines="$(MlaunchPath) $(MlaunchInstallArguments)" |
| 70 | + Overwrite="true" |
| 71 | + WriteOnlyWhenDifferent="true" |
| 72 | + Condition="'$(MlaunchInstallScript)' != ''" |
| 73 | + /> |
| 74 | + </Target> |
| 75 | + |
| 76 | + <Target Name="_InstallMobile" DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;ComputeMlaunchInstallArguments" Condition="'$(_SdkIsSimulator)' == 'false'"> |
| 77 | + <Exec SessionId="$(BuildSessionId)" Command="'$(MlaunchPath)' $(MlaunchInstallArguments)" /> |
| 78 | + </Target> |
| 79 | + |
| 80 | + <Target Name="ComputeMlaunchRunArguments" DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;_DetectAppManifest;_ShowRunHelpConditioned;_ComputeMlaunchRunArguments" Condition="'$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'" /> |
| 81 | + |
| 82 | + <Target Name="_ComputeMlaunchRunArguments" Condition="'$(Help)' != 'true'"> |
| 83 | + <!-- Launching from the command line on windows hasn't been implemented: https://github.com/dotnet/macios/issues/16609 --> |
| 84 | + <Error Condition="$([MSBuild]::IsOSPlatform('windows'))" Text="It's currently not supported to launch an app from the command line on Windows." /> |
| 85 | + <Error Condition="!Exists('$(_AppBundleManifestPath)')" Text="The app must be built before the arguments to launch the app using mlaunch can be computed." /> |
| 86 | + |
| 87 | + <PropertyGroup> |
| 88 | + <!-- capture output by default --> |
| 89 | + <_MlaunchCaptureOutput Condition="'$(_MlaunchCaptureOutput)' == ''">true</_MlaunchCaptureOutput> |
| 90 | + <!-- wait for exit by default --> |
| 91 | + <_MlaunchWaitForExit Condition="'$(_MlaunchWaitForExit)' == ''">true</_MlaunchWaitForExit> |
| 92 | + <!-- don't set standard output/error path, mlaunch will by default write to stdout/stderr --> |
| 93 | + </PropertyGroup> |
| 94 | + <ItemGroup> |
| 95 | + <MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_MODE__=$(XamarinDebugMode)" Condition="'$(XamarinDebugMode)' != ''" /> |
| 96 | + <MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_PORT__=$(XamarinDebugPort)" Condition="'$(XamarinDebugPort)' != ''" /> |
| 97 | + <MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_HOSTS__=$(XamarinDebugHosts.Replace(';', '%3B'))" Condition="'$(XamarinDebugHosts)' != ''" /> |
| 98 | + <MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_CONNECT_TIMEOUT__=$(XamarinDebugConnectTimeout)" Condition="'$(XamarinDebugConnectTimeout)' != ''" /> |
| 99 | + <!-- 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 --> |
| 100 | + <MlaunchAdditionalArguments Include="$(MlaunchAdditionalArgumentsProperty)" Condition="'$(MlaunchAdditionalArgumentsProperty)' != ''" /> |
| 101 | + </ItemGroup> |
| 102 | + <GetMlaunchArguments |
| 103 | + SessionId="$(BuildSessionId)" |
| 104 | + AdditionalArguments="@(MlaunchAdditionalArguments)" |
| 105 | + AppManifestPath="$(_AppBundleManifestPath)" |
| 106 | + CaptureOutput="$(_MlaunchCaptureOutput)" |
| 107 | + DeviceName="$(Device)" |
| 108 | + EnvironmentVariables="@(MlaunchEnvironmentVariables)" |
| 109 | + LaunchApp="$(_AppBundlePath)" |
| 110 | + MlaunchPath="$(MlaunchPath)" |
| 111 | + SdkIsSimulator="$(_SdkIsSimulator)" |
| 112 | + SdkDevPath="$(_SdkDevPath)" |
| 113 | + SdkVersion="$(_SdkVersion)" |
| 114 | + StandardErrorPath="$(_MlaunchStandardErrorPath)" |
| 115 | + StandardOutputPath="$(_MlaunchStandardOutputPath)" |
| 116 | + TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" |
| 117 | + WaitForExit="$(_MlaunchWaitForExit)" |
| 118 | + > |
| 119 | + <Output TaskParameter="MlaunchArguments" PropertyName="MlaunchRunArguments" /> |
| 120 | + </GetMlaunchArguments> |
| 121 | + |
| 122 | + <WriteLinesToFile |
| 123 | + File="$(MlaunchRunScript)" |
| 124 | + Lines="$(MlaunchPath) $(MlaunchRunArguments)" |
| 125 | + Overwrite="true" |
| 126 | + WriteOnlyWhenDifferent="true" |
| 127 | + Condition="'$(MlaunchRunScript)' != ''" |
| 128 | + /> |
| 129 | + |
| 130 | + <PropertyGroup> |
| 131 | + <RunCommand>$(MlaunchPath)</RunCommand> |
| 132 | + <RunArguments>$(MlaunchRunArguments) -- </RunArguments> |
| 133 | + </PropertyGroup> |
| 134 | + </Target> |
| 135 | + |
| 136 | + <!-- This is only needed for mobile platforms, RunCommand and RunArguments are defined for macOS in Microsoft.macOS.Sdk.targets. --> |
| 137 | + <Target |
| 138 | + Name="_PrepareRunMobile" |
| 139 | + BeforeTargets="ComputeRunArguments" |
| 140 | + DependsOnTargets="_InstallMobile;ComputeMlaunchRunArguments" |
| 141 | + Condition="'$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'"> |
| 142 | + </Target> |
| 143 | + |
| 144 | + <!-- |
| 145 | + *********************************************************************************************** |
| 146 | + ComputeAvailableDevices |
| 147 | +
|
| 148 | + Target that queries available devices and simulators. |
| 149 | + This target is called by 'dotnet run' to support device selection. |
| 150 | + Returns @(Devices) items that always has these metadata: Description, Type, OSVersion, UDID, RuntimeIdentifier |
| 151 | + (but others might be present too, for debug purposes, depending on whether it's a simulator or a device) |
| 152 | +
|
| 153 | + See: https://github.com/dotnet/sdk/blob/2b9fc02a265c735f2132e4e3626e94962e48bdf5/documentation/specs/dotnet-run-for-maui.md |
| 154 | + *********************************************************************************************** |
| 155 | + --> |
| 156 | + <Target Name="ComputeAvailableDevices" |
| 157 | + DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;" |
| 158 | + Condition="'$(_PlatformName)' == 'iOS' Or '$(_PlatformName)' == 'tvOS'" |
| 159 | + Returns="@(Devices)"> |
| 160 | + <PropertyGroup> |
| 161 | + <_FilterDevicesToRuntimeIdentifier Condition="'$(_XamarinUsingDefaultRuntimeIdentifier)' != 'true'">$(RuntimeIdentifier)</_FilterDevicesToRuntimeIdentifier> |
| 162 | + </PropertyGroup> |
| 163 | + <GetAvailableDevices |
| 164 | + Condition="'$(IsMacEnabled)' == 'true'" |
| 165 | + SessionId="$(BuildSessionId)" |
| 166 | + AppBundleManifestPath="$(_AppBundleManifestPath)" |
| 167 | + RuntimeIdentifier="$(_FilterDevicesToRuntimeIdentifier)" |
| 168 | + SdkDevPath="$(_SdkDevPath)" |
| 169 | + TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" |
| 170 | + Verbose="$(Verbose)" |
| 171 | + > |
| 172 | + <Output TaskParameter="Devices" ItemName="Devices" /> |
| 173 | + <Output TaskParameter="DiscardedDevices" ItemName="DiscardedDevices" /> |
| 174 | + </GetAvailableDevices> |
| 175 | + </Target> |
| 176 | + |
| 177 | +</Project> |
0 commit comments