Skip to content

Forward debugger ports for dotnet run - #12578

Open
jonathanpeppers wants to merge 1 commit into
mainfrom
jonathanpeppers-align-android-run-targets
Open

Forward debugger ports for dotnet run#12578
jonathanpeppers wants to merge 1 commit into
mainfrom
jonathanpeppers-align-android-run-targets

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Summary

  • route both WaitForExit=true and WaitForExit=false ComputeRunArguments paths through Microsoft.Android.Run
  • pass the existing AndroidSdbTargetPort / AndroidSdbHostPort values as a generic ADB forward mapping when AndroidAttachDebugger=true and AndroidDebuggerServer=true
  • add repeatable generic --forward-port and --reverse-port runner options
  • preserve the existing legacy Run, _Run, RunActivity, Mono debugger, and JDWP behavior unchanged

Background

dotnet run and the dotnet run --no-build child launched by dotnet watch execute the command returned by ComputeRunArguments; they do not invoke _Run. The debugger properties therefore reached MSBuild, but the legacy _Run target that established adb forward never executed.

This change establishes the requested port mapping in Microsoft.Android.Run before launching the application. WaitForExit=false uses the same runner with --no-wait, preserving the non-blocking launch behavior while ensuring forwarding works in both modes.

CoreCLR debugger configuration remains owned by vscode-maui, which ships the native debugger libraries and configures the runtime. See DevDiv/vscode-maui PR 716837 for that implementation.

A broader cleanup is intentionally deferred to .NET 12: #12577 tracks unifying the Run target behavior, deleting _Run, and removing obsolete Mono-specific launch paths.

Validation

  • built Microsoft.Android.Run for net10.0
  • validated Microsoft.Android.Sdk.Application.targets as XML
  • added focused ComputeRunArguments coverage for waiting, no-wait, debugger-server, and forwarding behavior

The full Xamarin.Android.Build.Tests assembly was not run because this checkout does not contain the locally built Android SDK/reference packs.

Route both ComputeRunArguments wait modes through Microsoft.Android.Run, add generic ADB TCP mappings, and preserve legacy Run and _Run behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f13f2ddd-fcd8-4c74-a37a-fdf6855b0d36
Copilot AI lite review requested due to automatic review settings August 28, 2026 16:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes dotnet run / dotnet watch Android debugger port-forwarding by ensuring the ComputeRunArguments launch path always goes through Microsoft.Android.Run, where ADB port mappings can be established before launching the app (including the WaitForExit=false/non-blocking mode).

Changes:

  • Route both WaitForExit=true and WaitForExit=false ComputeRunArguments execution through Microsoft.Android.Run, using --no-wait / --no-wake-device for the non-blocking mode.
  • Add generic repeatable --forward-port / --reverse-port options to Microsoft.Android.Run, and have ComputeRunArguments emit a forward mapping when AndroidAttachDebugger=true and AndroidDebuggerServer=true.
  • Add a focused regression test asserting that ComputeRunArguments includes the expected --forward-port arguments (and suppresses legacy --debugger-* args).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildOrderTests.cs Adds regression coverage to validate ComputeRunArguments emits generic port-forwarding args in both wait and no-wait modes.
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Application.targets Updates ComputeRunArguments to consistently invoke Microsoft.Android.Run and pass through forwarding + no-wait/no-wake flags as needed.
src/Microsoft.Android.Run/Program.cs Implements --no-wait, plus repeatable --forward-port / --reverse-port configuration and applies the mappings before app launch.

Comment thread src/Microsoft.Android.Run/Program.cs
@jonathanpeppers

Copy link
Copy Markdown
Member Author

/review

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Android PR Reviewer has started processing this issue comment

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.

2 participants