Skip to content

Commit 0304643

Browse files
[Microsoft.Android.Run] Add simple console app for dotnet run
Fixes: #10645 For alignment with other platforms, including `dotnet new console`, `dotnet run` for Android should: * Show console output for the launched process * Exit if the app closes * Close the app on Ctrl+C A one-liner like this is *close*: adb shell 'am start -S -W -n "PACKAGE/ACTIVITY"; pid=$(pidof PACKAGE); logcat --pid=$pid' But then Ctrl+C does not close the app, so to wire this all together, add a simple console app to be invoked by `dotnet run`. We do not initially intend for this app to be run directly by users, so it is placed in the `tools` folder of the SDK pack and not a .NET global tool. New MSBuild properties: `$(WaitForExit)` * Default: (empty) * When `false`, allow users to disable waiting for the app to exit, which is useful for our existing tests. `$(_AndroidRunPath)` * Default: `$(MSBuildThisFileDirectory)..\tools\Microsoft.Android.Run.dll` * Allows overriding the path to the `Microsoft.Android.Run` assembly. `$(_AndroidRunExtraArgs)` * Default: (empty) * Allows extra args like `--verbose` passed in
1 parent 17c5317 commit 0304643

File tree

9 files changed

+566
-23
lines changed

9 files changed

+566
-23
lines changed

Directory.Build.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<!-- NuGet Package Versions -->
44
<ItemGroup>
5+
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
56
<PackageReference Update="Microsoft.Win32.Registry" Version="5.0.0" />
67
<PackageReference Update="System.CodeDom" Version="9.0.8" />
78
<PackageReference Update="Irony" Version="1.1.0" />

Documentation/docs-mobile/building-apps/build-properties.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,3 +1819,21 @@ This MSBuild property replaces the
18191819
Xamarin.Android. This is the same property used for [Blazor WASM][blazor].
18201820

18211821
[blazor]: /aspnet/core/blazor/host-and-deploy/webassembly/#ahead-of-time-aot-compilation
1822+
1823+
## WaitForExit
1824+
1825+
A boolean property that controls the behavior of `dotnet run` when launching
1826+
Android applications.
1827+
1828+
When `$(WaitForExit)` not `false` (the default), `dotnet run` will:
1829+
1830+
* Launch the Android application
1831+
* Stream `logcat` output filtered to the application's process
1832+
* Wait for the application to exit or for the user to press Ctrl+C
1833+
* Force-stop the application when Ctrl+C is pressed
1834+
1835+
When `$(WaitForExit)` is `false`, `dotnet run` will simply launch the
1836+
application using `adb shell am start` and return immediately without
1837+
waiting for the application to exit or streaming any output.
1838+
1839+
Introduced in .NET 11.

Xamarin.Android.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.Aidl"
2525
EndProject
2626
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Build.Tasks", "src\Xamarin.Android.Build.Tasks\Xamarin.Android.Build.Tasks.csproj", "{3F1F2F50-AF1A-4A5A-BEDB-193372F068D7}"
2727
EndProject
28+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Android.Run", "src\Microsoft.Android.Run\Microsoft.Android.Run.csproj", "{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}"
29+
EndProject
2830
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Android.Sdk.ILLink", "src\Microsoft.Android.Sdk.ILLink\Microsoft.Android.Sdk.ILLink.csproj", "{71FE54FA-0BF5-48EF-ACAA-17557B28C9F4}"
2931
EndProject
3032
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.Bytecode", "external\Java.Interop\src\Xamarin.Android.Tools.Bytecode\Xamarin.Android.Tools.Bytecode.csproj", "{B17475BC-45A2-47A3-B8FC-62F3A0959EE0}"
@@ -169,6 +171,10 @@ Global
169171
{3F1F2F50-AF1A-4A5A-BEDB-193372F068D7}.Debug|AnyCPU.Build.0 = Debug|Any CPU
170172
{3F1F2F50-AF1A-4A5A-BEDB-193372F068D7}.Release|AnyCPU.ActiveCfg = Release|Any CPU
171173
{3F1F2F50-AF1A-4A5A-BEDB-193372F068D7}.Release|AnyCPU.Build.0 = Release|Any CPU
174+
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
175+
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Debug|AnyCPU.Build.0 = Debug|Any CPU
176+
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Release|AnyCPU.ActiveCfg = Release|Any CPU
177+
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Release|AnyCPU.Build.0 = Release|Any CPU
172178
{71FE54FA-0BF5-48EF-ACAA-17557B28C9F4}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
173179
{71FE54FA-0BF5-48EF-ACAA-17557B28C9F4}.Debug|AnyCPU.Build.0 = Debug|Any CPU
174180
{71FE54FA-0BF5-48EF-ACAA-17557B28C9F4}.Release|AnyCPU.ActiveCfg = Release|Any CPU

build-tools/create-packs/Microsoft.Android.Sdk.proj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ core workload SDK packs imported by WorkloadManifest.targets.
6565
<FilesToPackage Include="$(MicrosoftAndroidSdkOutDir)generator.dll" TargetPath="tools" />
6666
<FilesToPackage Include="$(MicrosoftAndroidSdkOutDir)generator.pdb" TargetPath="..\tools" IsSymbolFile="true" />
6767
<FilesToPackage Include="$(MicrosoftAndroidSdkOutDir)generator.runtimeconfig.json" TargetPath="tools" />
68+
<FilesToPackage Include="$(MicrosoftAndroidSdkOutDir)Microsoft.Android.Run.dll" TargetPath="tools" />
69+
<FilesToPackage Include="$(MicrosoftAndroidSdkOutDir)Microsoft.Android.Run.pdb" TargetPath="..\tools" IsSymbolFile="true" />
70+
<FilesToPackage Include="$(MicrosoftAndroidSdkOutDir)Microsoft.Android.Run.runtimeconfig.json" TargetPath="tools" />
6871
<FilesToPackage Include="@(VersionFiles)" TargetPath="tools" />
6972
<FilesToPackage Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\Sdk\**" TargetPath="Sdk" />
7073
<FilesToPackage Include="$(XamarinAndroidSourcePath)src\Microsoft.Android.Sdk.ILLink\PreserveLists\**" TargetPath="PreserveLists" />
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="..\..\Configuration.props" />
3+
4+
<PropertyGroup>
5+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
6+
<OutputPath>$(MicrosoftAndroidSdkOutDir)</OutputPath>
7+
<OutputType>Exe</OutputType>
8+
<TargetFramework>$(DotNetTargetFramework)</TargetFramework>
9+
<RootNamespace>Microsoft.Android.Run</RootNamespace>
10+
<ImplicitUsings>enable</ImplicitUsings>
11+
<Nullable>enable</Nullable>
12+
<DebugType>portable</DebugType>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
17+
<PackageReference Include="Mono.Options" Version="$(MonoOptionsVersion)" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\..\external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj" />
22+
</ItemGroup>
23+
24+
</Project>

0 commit comments

Comments
 (0)