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

@jonathanpeppers jonathanpeppers commented Aug 28, 2026

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

We are testing the debugger connection through dotnet watch, and these changes facilitate that scenario. dotnet watch launches a dotnet run --no-build child process, which executes the command returned by ComputeRunArguments; it does 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. Both WaitForExit=true and WaitForExit=false use the runner, so forwarding works for direct dotnet run and the child process launched by dotnet watch without changing the legacy MSBuild Run / _Run paths.

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

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12578

@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Aug 28, 2026

@github-actions github-actions Bot 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.

⚠️ Needs Changes

Findings: 0 errors · 0 warnings · 1 suggestion

The implementation consistently routes both wait modes through Microsoft.Android.Run and preserves the legacy debugger-port direction. Please add runner-level coverage for the new generic port-mapping CLI surface; the current test only verifies MSBuild argument composition.

CI currently has 37 successful checks, with 7 emulator lanes still running and the aggregate build queued.

Generated by Android PR Reviewer for #12578 · gpt56 · 117.9 AIC · ⌖ 8.86 AIC · ⊞ 25.7K
Comment /review to run again

!int.TryParse (ports [1], out int destination) ||
source is < 1 or > 65535 ||
destination is < 1 or > 65535) {
throw new OptionException ("Expected two TCP ports between 1 and 65535 in SOURCE:DESTINATION format.", option);

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.

🤖 💡 Testing — The added test only inspects the generated MSBuild argument string, so neither new runner option is exercised. Invalid/boundary mappings, repeated mappings, and adb reverse command construction can regress unnoticed. Please add focused runner-level coverage around port parsing and command generation for both forward and reverse mappings.

Rule: Test edge cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants