.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。 這不是警告或無聲的 no-op。

對於 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>