Skip to content

[Xamarin.Android.Tools] Quote sdkmanager package IDs - #13621

Merged
jonathanpeppers merged 3 commits into
mainfrom
rmarinho-fix-issue-13617
Nov 18, 2026
Merged

jonathanpeppers merged 3 commits into
mainfrom
rmarinho-fix-issue-13617

Conversation

@rmarinho

@rmarinho rmarinho commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Fixes: #13617

Windows Command-line Tools 23 can split semicolon-delimited package IDs such as build-tools;37.0.0 when sdkmanager.bat is launched with ProcessStartInfo.ArgumentList. The batch shim then exits successfully without installing the requested package.

Launch Windows batch shims through the system cmd.exe with delayed expansion disabled, validate package IDs, and explicitly quote each argument at the cmd.exe boundary. The regression test invokes SdkManager.InstallAsync() against a stub batch launcher and verifies that a semicolon-delimited package ID arrives as one argument. Focused validation tests also verify that unsafe package IDs are rejected before SDK lookup.

Validation

  • dotnet build src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj -v:minimal — passed with 0 warnings and 0 errors.
  • dotnet test tests\Xamarin.Android.Tools.AndroidSdk-Tests\Xamarin.Android.Tools.AndroidSdk-Tests.csproj -v:minimal --filter "Name~InstallAsync_InvalidPackageId_ThrowsBeforeSdkLookup|Name~InstallAsync_WindowsBatch_PreservesPackageId" — passed 3 tests.
  • dotnet test tests\Xamarin.Android.Tools.AndroidSdk-Tests\Xamarin.Android.Tools.AndroidSdk-Tests.csproj -v:minimal --filter "Name!~CreateProcessStartInfo_" — passed 413 tests; 39 platform-specific tests skipped.

The unfiltered project run has three pre-existing CreateProcessStartInfo_* failures because the netstandard2.0 library build uses ProcessStartInfo.Arguments while those tests assert ArgumentList.

Windows Command-line Tools 23 can split semicolon-delimited package IDs when sdkmanager.bat is launched with ProcessStartInfo.ArgumentList.  The batch shim then exits successfully without installing the requested package.

Invoke the batch launcher through the system cmd.exe, validate package IDs, and explicitly quote each argument at the cmd.exe boundary.  Cover the behavior through SdkManager.InstallAsync().

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 14:24

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.

🟡 Changes recommended

The new package-ID validation lacks tests confirming that InstallAsync and UninstallAsync reject invalid inputs before SDK lookup or process launch while accepting valid slash-separated IDs.

1 open issue
What changed in this PR

Addresses #13617 in the shared Android SDK tooling by preserving semicolon-delimited package IDs when launching Windows sdkmanager.bat, avoiding successful exits without installing the requested packages.

Changes:

  • Launches Windows batch shims through system cmd.exe, with explicit argument quoting and delayed expansion disabled.
  • Validates package IDs before installation or removal.
  • Adds a Windows regression test verifying that a complete package ID reaches a stub batch launcher.
File Description
tests/​Xamarin.Android.Tools.AndroidSdk-Tests/​SdkManagerTests.cs Adds a batch-launch regression test for semicolon-delimited IDs.
src/​Xamarin.Android.Tools.AndroidSdk/​SdkManager.Process.cs Adds explicit Windows batch launching and argument quoting.
src/​Xamarin.Android.Tools.AndroidSdk/​SdkManager.Packages.cs Rejects empty or unsupported package IDs before execution.

Review effort: Balanced

Verify that unsafe package IDs are rejected before SDK lookup and that both semicolon- and slash-separated package IDs reach the Windows batch launcher unchanged.

Co-authored-by: Copilot App <[email protected]>

@jonathanpeppers jonathanpeppers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 Review: the fix is correct. These comments are about how to make it simpler.

Remove the unreachable non-batch launcher path and redundant package validation cases.  Keep the SDK path in an environment variable so cmd.exe does not expand metacharacters within it.

Co-authored-by: Copilot App <[email protected]>
@jonathanpeppers
jonathanpeppers merged commit 667e27a into main Nov 18, 2026
38 checks passed
@jonathanpeppers
jonathanpeppers deleted the rmarinho-fix-issue-13617 branch November 18, 2026 21:08
@jonathanpeppers

Copy link
Copy Markdown
Member

/backport to release/11.0.1xx

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0.1xx (link to workflow run)

jonathanpeppers pushed a commit that referenced this pull request Nov 19, 2026
Fixes: #13617

Windows Command-line Tools 23 can split semicolon-delimited package IDs such as `build-tools;37.0.0` when `sdkmanager.bat` is launched with `ProcessStartInfo.ArgumentList`. The batch shim then exits successfully without installing the requested package.

Launch Windows batch shims through the system `cmd.exe` with delayed expansion disabled, validate package IDs, and explicitly quote each argument at the `cmd.exe` boundary. The regression test invokes `SdkManager.InstallAsync()` against a stub batch launcher and verifies that a semicolon-delimited package ID arrives as one argument. Focused validation tests also verify that unsafe package IDs are rejected before SDK lookup.

Co-authored-by: Rui Marinho <[email protected]>
Co-authored-by: Copilot App <[email protected]>
simonrozsival added a commit that referenced this pull request Nov 21, 2026
The rebase onto cc7cbf6 kept the pre-rebase MSTest conversions of
files that main had changed since aa688ac, which reverted those
changes and broke the build. For each affected file, convert main's
old and new NUnit versions with the same converter and merge the
difference into the MSTest file:

  * cca255c (#13592): drop the Android lint tests and assertions.
  * 5b32fb1 (#13602): add RelativeDirectoriesUseProjectDirectory and
    the -mt CollectNonEmptyDirectories coverage.
  * 78ef747 (#13655): add OpenGenericProxiesKeepTheReflectionActivationConstructor.
  * 18b8940 (#13585): add the generator nullability/obsolete tests.
  * dcbd008 (#13580): add the AmbiguousFunctionMetadata_* tests.
  * 667e27a (#13621): add the sdkmanager package ID tests.
  * 5ecb8f7 (#13614): drop RunWithLoggingEnablesManagedTimingLogger.
  * 8287b17 (#13680), 4bfcc92 (#13681): restore the re-enabled
    tests and removed TODOs.
  * 5d81a0f (#13666): expect platform-tools 37.0.3.
  * 8442c75 (#13601): assert the pulled device TRX is deleted.

Also drop the EnableNUnitRunner/OutputType lines that 857f463
(#13563) added to Xamarin.Android.Build.Tests and MSBuildDeviceIntegration;
MSTestReferences.projitems sets both.

Co-authored-by: Copilot App <[email protected]>
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.

Windows sdkmanager.bat splits semicolon-delimited package IDs with cmdline-tools 23

3 participants