Skip to content

Conversation

@jonathanpeppers
Copy link
Member

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

@jonathanpeppers
Copy link
Member Author

I'm not able to test this end-to-end, because the build of dotnet/dotnet we have is missing this change:

It is correct in dotnet/sdk/main, but not when I decompile dotnet.dll:

image

I'll see if I can get a newer dotnet/dotnet to unblock me.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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
@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/Microsoft.Android.Run branch from 0304643 to 8aa2dd1 Compare December 16, 2025 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dotnet run console behavior

3 participants