Skip to content

[Microsoft.Android.Build.Tasks] Register all net11.0 tasks with conditional Runtime="NET" UsingTask - #13195

Merged
simonrozsival merged 1 commit into
mainfrom
simonrozsival-fix-usingtask-runtime-net
Oct 20, 2026
Merged

simonrozsival merged 1 commit into
mainfrom
simonrozsival-fix-usingtask-runtime-net

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Summary of Changes

  • Update all remaining <UsingTask> registrations for $(_MicrosoftAndroidBuildTasksAssembly) across .targets files (Xamarin.Android.Common.targets, Xamarin.Android.Assets.targets, Xamarin.Android.Javac.targets, Microsoft.Android.Sdk.NativeAOT.targets, Microsoft.Android.Sdk.R8JniRemapping.targets, and Microsoft.Android.Sdk.TypeMap.Proguard.targets) to use the standard two-line conditional Full / Core pattern:
    <UsingTask TaskName="Microsoft.Android.Tasks.<TaskName>" AssemblyFile="$(_MicrosoftAndroidBuildTasksAssembly)" Runtime="NET" TaskFactory="TaskHostFactory" Condition=" '$(MSBuildRuntimeType)' == 'Full' " />
    <UsingTask TaskName="Microsoft.Android.Tasks.<TaskName>" AssemblyFile="$(_MicrosoftAndroidBuildTasksAssembly)" Runtime="NET" Condition=" '$(MSBuildRuntimeType)' == 'Core' " />
  • This ensures Microsoft.Android.Build.Tasks.dll (net11.0) runs out-of-proc via TaskHostFactory with Runtime="NET" on Visual Studio (MSBuild.exe, $(MSBuildRuntimeType) == 'Full') and in-proc with Runtime="NET" on dotnet build ($(MSBuildRuntimeType) == 'Core').
  • Remove redundant MSBuildRuntime="NET" attributes from task invocations now that <UsingTask> specifies Runtime="NET".
  • Update comments in Microsoft.Android.Build.Tasks.csproj and CompressAssemblies.cs to reference <UsingTask ... Runtime="NET" />.

Contributes to / Resolves

  • N/A

Verification

  • dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj — passed (727 passed, 12 skipped, 0 failed)
  • dotnet build src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj — passed (0 warnings, 0 errors)
  • dotnet build src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj -p:DisableApiCompatibilityCheck=true — passed (0 warnings, 0 errors)
  • Verified zero bare <UsingTask ... AssemblyFile="$(_MicrosoftAndroidBuildTasksAssembly)" /> or MSBuildRuntime="NET" remain in src/.

Documentation

  • N/A (internal MSBuild task registration update)

…tional Runtime="NET" UsingTask

Tasks in `Microsoft.Android.Build.Tasks.dll` target `net11.0`. On .NET Framework MSBuild (`$(MSBuildRuntimeType) == 'Full'`), loading a `net11.0` task assembly without `TaskFactory="TaskHostFactory"` and `Runtime="NET"` on `<UsingTask>` fails or attempts in-process loading on .NET Framework 4.7.2, while on .NET MSBuild (`$(MSBuildRuntimeType) == 'Core'`), `Runtime="NET"` runs in-process without spawning an out-of-proc task host.

Update all remaining `<UsingTask>` registrations for `$(_MicrosoftAndroidBuildTasksAssembly)` to use the standard two-line `Full` / `Core` conditional registration pattern and remove redundant `MSBuildRuntime="NET"` attributes from task invocations.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 19, 2026 14:40

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.

🔵 Needs a closer look

The Windows task-host path has a compression-cache regression and lacks integration validation.

1 open issue
What changed in this PR

Centralizes runtime selection for modern .NET Android build tasks across Visual Studio and dotnet build.

Changes:

  • Adds conditional Full/Core task registrations.
  • Removes invocation-level runtime overrides.
  • Updates explanatory comments; task implementations are unchanged.
File Description
src/​Xamarin.Android.Build.Tasks/​Xamarin.Android.Common.targets Updates packaging and compression task registrations.
src/​Xamarin.Android.Build.Tasks/​MSBuild/​Xamarin/​Android/​Xamarin.Android.Javac.targets Updates Java archive task registration.
src/​Xamarin.Android.Build.Tasks/​MSBuild/​Xamarin/​Android/​Xamarin.Android.Assets.targets Updates asset-pack task registration.
src/​Xamarin.Android.Build.Tasks/​Microsoft.Android.Sdk/​targets/​Microsoft.Android.Sdk.TypeMap.Proguard.targets Adds runtime selection for typemap tasks.
src/​Xamarin.Android.Build.Tasks/​Microsoft.Android.Sdk/​targets/​Microsoft.Android.Sdk.R8JniRemapping.targets Updates remapping task runtime selection.
src/​Xamarin.Android.Build.Tasks/​Microsoft.Android.Sdk/​targets/​Microsoft.Android.Sdk.NativeAOT.targets Updates NativeAOT task runtime selection.
src/​Microsoft.Android.Build.Tasks/​Tasks/​CompressAssemblies.cs Updates runtime-selection documentation only.
src/​Microsoft.Android.Build.Tasks/​Microsoft.Android.Build.Tasks.csproj Updates assembly-purpose comments only.

Review effort: Balanced

simonrozsival added a commit that referenced this pull request Oct 19, 2026
…nal Runtime="NET" UsingTask

Match the pattern in #13195 by registering
Microsoft.Android.Tasks.GenerateNativeApplicationConfigSources with the
conditional Full/Core Runtime="NET" <UsingTask> declarations and
removing the redundant MSBuildRuntime="NET" attribute on the task
invocation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Oct 20, 2026
@simonrozsival
simonrozsival enabled auto-merge (squash) October 20, 2026 15:01
@simonrozsival
simonrozsival merged commit fa7d557 into main Oct 20, 2026
42 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-fix-usingtask-runtime-net branch October 20, 2026 19:17
simonrozsival added a commit that referenced this pull request Oct 27, 2026
…oid.Build.Tasks (#13199)

Context: bf732908d0250966278042dc63a5f6f7ec2ca614
Context: 12c2d57
Context: 9e66448
Context: fa7d557
Context: a3c24de

`Xamarin.Android.Build.Tasks.dll` targets `netstandard2.0` so that MSBuild tasks can load in both .NET Framework (`MSBuild.exe` in Visual Studio) and .NET (`dotnet build`).  Because `netstandard2.0` does not include `System.IO.Hashing` in the shared framework, referencing `System.IO.Hashing` from `Xamarin.Android.Build.Tasks.csproj` deposits the `netstandard2.0` flavor of `System.IO.Hashing.dll` (whose `Span<T>` overloads bind to `System.Memory`) into the SDK's `tools/` directory.  As noted in bf73290, `net11.0` tasks had to be placed in `tools/net/Microsoft.Android.Build.Tasks.dll` so they would not resolve the `netstandard2.0` `System.IO.Hashing.dll` and fail with `MissingMethodException`.

After commits 9e66448 (#13197) and a3c24de (#13198) removed unused hashing helpers and moved `<CreateAssemblyStore/>` to `Microsoft.Android.Build.Tasks.dll`, `<GenerateNativeApplicationConfigSources/>` (via `CoreClrBootstrapBuilder`) was the last remaining consumer of `System.IO.Hashing.Crc32` in `Xamarin.Android.Build.Tasks.dll`.

Move `<GenerateNativeApplicationConfigSources/>` and its supporting types from `src/Xamarin.Android.Build.Tasks` (`netstandard2.0`) to `src/Microsoft.Android.Build.Tasks` (`net11.0`) so `Xamarin.Android.Build.Tasks.dll` no longer needs `System.IO.Hashing`:

  * Move `GenerateNativeApplicationConfigSources`, `CoreClrBootstrapBuilder`, `RuntimePropertiesParser`, and `BundleConfigSplitConfigsChecker` to `src/Microsoft.Android.Build.Tasks/` under `namespace Microsoft.Android.Tasks`.
  * Compute DSO cache entry hashes in `CoreClrBootstrapBuilder.Write()` directly via `System.IO.Hashing.Crc32.HashToUInt32()`, and add an explicit `System.IO.Hashing` `<PackageReference/>` to `Microsoft.Android.Build.Tasks.csproj`.
  * Remove the `CoreClrBootstrapBlob.cs` and `EnvironmentBuilder.cs` source links from `Xamarin.Android.Build.Tasks.csproj`, as all callers now reside in `Microsoft.Android.Build.Tasks.dll`.
  * Move `MonoAndroidHelper.GetAssemblyCulture()`, `ParseAndroidRuntime()`, and `GetNormalizedNativeLibraryName()` into the shared `MonoAndroidHelper.Assemblies.cs` file (using `.IsNullOrEmpty()` so `#nullable enable` compiles cleanly on `netstandard2.0` as well as `net11.0`), and move `ELFHelper.IsJniLibrary()` into `CoreClrBootstrapBuilder` while removing unused symbol-lookup helpers from `ELFHelper`.
  * Define `PackageNamingPolicy` in `Microsoft.Android.Tasks` so `Microsoft.Android.Build.Tasks.csproj` remains self-contained without referencing `Java.Interop.Tools.TypeNameMappings`.
  * Update `Xamarin.Android.Common.targets` to register `Microsoft.Android.Tasks.GenerateNativeApplicationConfigSources` from `$(_MicrosoftAndroidBuildTasksAssembly)` using the conditional `Full` (`TaskHostFactory`) / `Core` `Runtime="NET"` `<UsingTask/>` pattern from fa7d557 (#13195), and update `$(_AndroidCoreClrBootstrapTaskAssembly)` in the `_AndroidGenerateCoreClrBootstrapInputs` target to track `$(_MicrosoftAndroidBuildTasksAssembly)`.
  * Move `GenerateNativeApplicationConfigSourcesTests`, `RuntimePropertiesParserTests`, and `EnvironmentBuilderTests` to `Microsoft.Android.Build.Tasks.Tests`, generating synthetic 32-bit (`AndroidTargetArch.Arm`) and 64-bit (`AndroidTargetArch.Arm64`) ELF JNI libraries via `AssemblyStoreElfWriter` and `ELFReader` so the tests run standalone without requiring a native build of `libtest-jni-library.so`.
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.

3 participants