Skip to content

Guard Mono-specific AOT targets for CoreCLR runtime, add XA1042 warning#11070

Open
Copilot wants to merge 3 commits intomainfrom
copilot/fix-mono-targets-with-coreclr
Open

Guard Mono-specific AOT targets for CoreCLR runtime, add XA1042 warning#11070
Copilot wants to merge 3 commits intomainfrom
copilot/fix-mono-targets-with-coreclr

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

Setting <RunAOTCompilation>true</RunAOTCompilation> in a project file (e.g. Directory.Build.props) causes build failures when switching from Mono to CoreCLR, because MonoAOTCompiler runs unconditionally regardless of the active runtime.

Changes

  • Microsoft.Android.Sdk.Aot.targets — Add '$(_AndroidRuntime)' == 'MonoVM' guard to the ImportGroup (MonoAOTCompiler SDK imports) and _AndroidAot target condition
  • Microsoft.Android.Sdk.DefaultProperties.targets — After RunAOTCompilation defaults are resolved, detect Mono-specific properties (RunAOTCompilation, EnableLLVM) set with non-MonoVM runtimes, reset them to false, and set flags for warning emission
  • Xamarin.Android.Common.targets — Emit new XA1042 warning when the flags are set; add $(PublishAot) condition to _NdkRequired so NativeAOT always requires the Android NDK
  • Resources.resx / Resources.Designer.cs — New XA1042 message
  • xa1042.md — Documentation for the new warning
  • AotTests.cs — Two tests: RunAOTCompilationWithCoreClrWarnsAndSkipsMonoAot and EnableLLVMWithCoreClrWarnsAndIsIgnored
  • AndroidDependenciesTests.cs — New NativeAotRequiresNdk test validating that NativeAOT always lists the NDK as a dependency

Example warning

warning XA1042: The MSBuild property 'RunAOTCompilation' is not compatible with the CoreCLR runtime and will be ignored.
Either remove the property or guard it with a condition: Condition="'$(UseMonoRuntime)' == 'true'"

Migration guidance

<!-- Before: breaks when switching to CoreCLR -->
<RunAOTCompilation>true</RunAOTCompilation>

<!-- After: only applies to Mono -->
<PropertyGroup Condition=" '$(UseMonoRuntime)' == 'true' ">
  <RunAOTCompilation>true</RunAOTCompilation>
</PropertyGroup>

…r Mono-specific properties used with non-MonoVM runtimes

Agent-Logs-Url: https://github.com/dotnet/android/sessions/a5ac81b3-0cd5-4a8a-9394-531fa1466274

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Mono targets execution when using CoreCLR runtime Guard Mono-specific AOT targets for CoreCLR runtime, add XA1042 warning Apr 2, 2026
Copilot AI requested a review from simonrozsival April 2, 2026 09:50
@jonathanpeppers jonathanpeppers marked this pull request as ready for review April 3, 2026 20:58
@jonathanpeppers jonathanpeppers self-requested a review as a code owner April 3, 2026 20:58
Copilot AI review requested due to automatic review settings April 3, 2026 20:58
@jonathanpeppers
Copy link
Copy Markdown
Member

@copilot we need to fix this test:

GetDependencyNdkRequiredConditions("EnableLLVM",True,NativeAOT)

When $(PublishAot) is true, we should require the Android NDK.

We may want to add an additional test so this is clearer.

Copy link
Copy Markdown
Contributor

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.

Pull request overview

This PR prevents Mono AOT build logic from running when a project is configured for non-Mono runtimes (CoreCLR/NativeAOT), and adds a dedicated warning (XA1042) to guide users who have Mono-only AOT properties set unconditionally (e.g., via Directory.Build.props).

Changes:

  • Guard MonoAOTCompiler SDK imports and _AndroidAot execution so they only run for MonoVM.
  • Detect RunAOTCompilation / EnableLLVM set under non-Mono runtimes, reset them to false, and emit XA1042 with actionable guidance.
  • Add XA1042 resource + documentation and add tests validating warning emission and successful builds under CoreCLR.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets Restricts MonoAOTCompiler SDK imports and _AndroidAot target to MonoVM runtime only.
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets Detects Mono-only properties under non-Mono runtimes, sets XA1042 flags, and resets the properties to false.
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets Emits XA1042 warnings when the corresponding flags are set.
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx Adds localized XA1042 warning message template.
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs Regenerates strongly-typed resource accessor for XA1042.
Documentation/docs-mobile/messages/xa1042.md Adds end-user documentation and migration guidance for XA1042.
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs Adds tests ensuring CoreCLR builds succeed and XA1042 is emitted when Mono-only properties are set.
Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Language not supported

…ated test

Agent-Logs-Url: https://github.com/dotnet/android/sessions/1e564b95-24aa-400d-b01f-f153bea868fd

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 3, 2026

@copilot we need to fix this test:

GetDependencyNdkRequiredConditions("EnableLLVM",True,NativeAOT)

...

Fixed in b2456ac. The issue was that my XA1042 change resets EnableLLVM to false for non-MonoVM runtimes, but NativeAOT still needs the NDK (it uses the NDK's clang compiler).

Two changes:

  1. Added <_NdkRequired Condition="'$(PublishAot)' == 'true'">true</_NdkRequired> to the GetAndroidDependencies target so NativeAOT always requires NDK regardless of EnableLLVM.
  2. Added a dedicated NativeAotRequiresNdk test that validates NativeAOT requires NDK without relying on any Mono-specific properties.

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.

[CoreCLR] Setting RunAOTCompilation in project file runs MonoAOTCompiler even with CoreCLR runtime

4 participants