From 0b6b41c8178df226985ce6c0a7135bcc00e796cd Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Sun, 28 Jun 2026 03:24:50 +0200 Subject: [PATCH] [TrimmableTypeMap] Don't stage shrunk assemblies into the shared runtime pack on NativeAOT CheckCodeBehindIsGenerated(NativeAOT) and CheckOldResourceDesignerWithWrongCasingIsRemoved(True,NativeAOT) failed intermittently in CI with: error XACIC7028: System.IO.FileNotFoundException: Could not find file '.../microsoft.netcore.app.runtime.nativeaot.android-arm64/.../lib/net11.0/shrunk/System.Xml.ReaderWriter.dll' at _RemoveRegisterAttribute (Xamarin.Android.Common.targets). The base _RemoveRegisterAttribute copies every @(_ResolvedAssemblies) into its @(_ShrunkAssemblies) location. For PublishTrimmed builds the framework/ user shrunk destinations live *inside the shared NuGet runtime pack* (.../runtimes//lib/net11.0/shrunk/). Because multiple test projects and the parallel per-RID inner builds all target those same shared files, they race and fail intermittently with FileNotFoundException on a clean pack cache. Locally the failure is masked by shrunk/ files left over from previous builds. On NativeAOT these managed framework/user assemblies are compiled to a native shared library by ILC and are never packaged, so the shrunk copies are only ever used as incremental-build inputs (CollectAssemblyFilesToCompress, the one task that reads their content, is already gated to non-NativeAOT). Override _RemoveRegisterAttribute in the trimmable typemap path to redirect the shrunk copies to a project-local intermediate directory instead of the shared pack. They are still produced with CopyIfChanged so the copies keep stable timestamps (preserving the @(_ShrunkAssemblies)/@(_ShrunkFrameworkAssemblies) incremental up-to-date checks), but nothing is ever written into the shared runtime pack. CoreCLR keeps the base behavior since it still packages the managed assemblies. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ...soft.Android.Sdk.TypeMap.Trimmable.targets | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.Trimmable.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.Trimmable.targets index 0a3ff223f63..47f63cc57aa 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.Trimmable.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.Trimmable.targets @@ -243,6 +243,51 @@ + + + + <_ShrunkAssemblies Remove="@(_ShrunkAssemblies)" /> + <_ShrunkAssemblies Include="@(_ResolvedAssemblies->'$(MonoAndroidIntermediateAssemblyDir)shrunk\%(DestinationSubPath)')" /> + <_ShrunkFrameworkAssemblies Remove="@(_ShrunkFrameworkAssemblies)" /> + <_ShrunkFrameworkAssemblies Include="@(_ResolvedFrameworkAssemblies->'$(MonoAndroidIntermediateAssemblyDir)shrunk\%(DestinationSubPath)')" /> + <_ShrunkUserAssemblies Remove="@(_ShrunkUserAssemblies)" /> + <_ShrunkUserAssemblies Include="@(_ResolvedUserAssemblies->'$(MonoAndroidIntermediateAssemblyDir)shrunk\%(DestinationSubPath)')" /> + + + + + +