diff --git a/Documentation/docs-mobile/messages/xa1042.md b/Documentation/docs-mobile/messages/xa1042.md new file mode 100644 index 00000000000..f57c6e6cbd2 --- /dev/null +++ b/Documentation/docs-mobile/messages/xa1042.md @@ -0,0 +1,45 @@ +--- +title: .NET for Android warning XA1042 +description: XA1042 warning code +ms.date: 04/02/2026 +f1_keywords: + - "XA1042" +--- + +# .NET for Android warning XA1042 + +## Example messages + +``` +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'" +``` + +## Issue + +This warning indicates that a Mono-specific MSBuild property is set in +the project file, but the project is configured to use a non-Mono +runtime (such as CoreCLR or NativeAOT). The property will have no +effect with the current runtime and will be ignored. + +Properties that trigger this warning include: +- `RunAOTCompilation` — Mono AOT compilation; CoreCLR uses `PublishReadyToRun` instead. +- `EnableLLVM` — Enables LLVM for the Mono AOT compiler. + +## Solution + +Remove the Mono-specific property from your project file or +`Directory.Build.props`, or guard it with a runtime condition: + +```xml + + true + +``` + +For CoreCLR, use `PublishReadyToRun` instead of `RunAOTCompilation`: + +```xml + + true + +``` diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets index d80be84d01c..3537c75fb4b 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets @@ -21,7 +21,7 @@ They run in a context of an inner build with a single $(RuntimeIdentifier). when $(MonoAOTCompilerTasksAssemblyPath) is blank: https://github.com/dotnet/runtime/blob/69711860262e44458bbe276393ea3eb9f7a2192a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.targets.in#L20-L25 --> - + @@ -39,7 +39,7 @@ They run in a context of an inner build with a single $(RuntimeIdentifier). diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets index e9c75e1667d..fd8c19234f1 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets @@ -119,6 +119,11 @@ true true false + + <_AndroidXA1042_RunAOTCompilation Condition=" '$(RunAOTCompilation)' == 'true' and '$(_AndroidRuntime)' != 'MonoVM' ">true + <_AndroidXA1042_EnableLLVM Condition=" '$(EnableLLVM)' == 'true' and '$(_AndroidRuntime)' != 'MonoVM' ">true + false + false <_AndroidXA1029 Condition=" '$(AotAssemblies)' != '' ">true <_AndroidXA1030 Condition=" '$(RunAOTCompilation)' == 'true' and '$(PublishTrimmed)' == 'false' ">true $(RunAOTCompilation) diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs index bc2d9a7d4d4..4b7c0de91fc 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs @@ -938,6 +938,15 @@ public static string XA1041 { } } + /// + /// Looks up a localized string similar to The MSBuild property '{0}' is not compatible with the {1} runtime and will be ignored. Either remove the property or guard it with a condition: Condition="'$(UseMonoRuntime)' == 'true'". + /// + public static string XA1042 { + get { + return ResourceManager.GetString("XA1042", resourceCulture); + } + } + /// /// Looks up a localized string similar to Use of AppDomain.CreateDomain() detected in assembly: {0}. .NET 6 and higher will only support a single AppDomain, so this API will no longer be available in .NET for Android once .NET 6 is released.. /// diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index d1ee02dc051..6d6eb3546f6 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -1007,6 +1007,13 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS The following are literal names and should not be translated: .NET. {0} - The MSBuild property that has the incorrect value. {1} - The current value of the property + + + + The MSBuild property '{0}' is not compatible with the {1} runtime and will be ignored. Either remove the property or guard it with a condition: Condition="'$(UseMonoRuntime)' == 'true'" + The following are literal names and should not be translated: MSBuild, UseMonoRuntime. +{0} - The MSBuild property name (e.g. RunAOTCompilation, EnableLLVM). +{1} - The name of the .NET runtime (e.g. CoreCLR, NativeAOT). diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs index 6a6b91aa900..09d36e7b02a 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs @@ -492,5 +492,37 @@ public void CheckWhetherLibcAndLibmAreReferencedInAOTLibraries () } } + [Test] + public void RunAOTCompilationWithCoreClrWarnsAndSkipsMonoAot () + { + var proj = new XamarinAndroidApplicationProject { + IsRelease = true, + }; + proj.SetRuntime (AndroidRuntime.CoreCLR); + proj.SetProperty ("RunAOTCompilation", "true"); + + using var b = CreateApkBuilder (); + Assert.IsTrue (b.Build (proj), "Build should have succeeded."); + StringAssertEx.Contains ("warning XA1042", b.LastBuildOutput, "Build output should contain warning XA1042"); + StringAssertEx.Contains ("RunAOTCompilation", b.LastBuildOutput, "Build output should mention RunAOTCompilation"); + StringAssertEx.Contains ("CoreCLR", b.LastBuildOutput, "Build output should mention CoreCLR"); + } + + [Test] + public void EnableLLVMWithCoreClrWarnsAndIsIgnored () + { + var proj = new XamarinAndroidApplicationProject { + IsRelease = true, + }; + proj.SetRuntime (AndroidRuntime.CoreCLR); + proj.SetProperty ("EnableLLVM", "true"); + + using var b = CreateApkBuilder (); + Assert.IsTrue (b.Build (proj), "Build should have succeeded."); + StringAssertEx.Contains ("warning XA1042", b.LastBuildOutput, "Build output should contain warning XA1042"); + StringAssertEx.Contains ("EnableLLVM", b.LastBuildOutput, "Build output should mention EnableLLVM"); + StringAssertEx.Contains ("CoreCLR", b.LastBuildOutput, "Build output should mention CoreCLR"); + } + } } diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index c2527d1954e..e6a46aab923 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -550,6 +550,16 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. ResourceName="XA1030" Condition=" $(_AndroidXA1030) == 'true' " /> + +