.NET for Android 错误 XA1044

示例消息

error XA1044: The MSBuild property 'RunAOTCompilation' is not compatible with the CoreCLR runtime. The build cannot continue while this property is enabled. Either remove the property or guard it with a condition: Condition="'$(UseMonoRuntime)' == 'true'"
error XA1044: The MSBuild property 'RunAOTCompilation' is not compatible with the CoreCLR runtime. The build cannot continue while this property is set to 'false'. Remove the property. Starting with .NET 11, set 'PublishReadyToRun' to 'false' to disable ReadyToRun (R2R) AOT compilation.

此消息建议的条件仅适用于支持 Mono 的目标。 在 .NET 11 中,$(UseMonoRuntime)=true 会因 NETSDK1242 而被拒绝;请改为删除仅适用于 Mono 的属性。

Issue

此错误指示在项目文件中设置了 Mono 特定的 MSBuild 属性,但项目配置为使用非 Mono 运行时,例如 CoreCLR 或 NativeAOT。 当属性是 true 时,生成会将其重置为 false,以便不将其传递给非 Mono 生成步骤,然后因 XA1044 而停止。 这既不是警告,也不是静默空操作。

对于 CoreCLR 应用程序,将 RunAOTCompilation 设置为 false 也会产生此错误。 它不会禁用 ReadyToRun 编译。 对于 NativeAOT,将其设置为 false 不会产生此错误。

触发此错误的属性包括:

  • RunAOTCompilation — 启用 Mono AOT 编译。
  • EnableLLVM — 为 Mono AOT 编译器启用 LLVM。

解决方案

从项目文件或 Directory.Build.props 中删除 Mono 特有的属性。 仅在项目文件中或仅适用于受支持的 .NET 10 及更早版本 Mono 目标的条件下保留它。

ReadyToRun 和 NativeAOT 是单独的编译模型。 它们并不是 Mono AOT 设置的逐一对应替代品。

从 .NET 11 开始,要为 CoreCLR 应用程序禁用 ReadyToRun (R2R) AOT 编译,请移除 RunAOTCompilation 并设置 PublishReadyToRun 改为 false :

<PropertyGroup>
  <PublishReadyToRun>false</PublishReadyToRun>
</PropertyGroup>