From 0dae187456dc3813572f65509a1f8942b06bfbd2 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 28 Nov 2025 17:41:02 +0100 Subject: [PATCH 1/7] [net11.0] [dotnet] Don't allow setting PublishTrimmed to any value. This is a workaround https://github.com/dotnet/runtime/issues/108269, where setting PublishTrimmed=true causes problems. --- dotnet/targets/Xamarin.Shared.Sdk.targets | 15 ++++++++---- tests/dotnet/UnitTests/PublishTrimmedTest.cs | 24 ++++++++++++-------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index b997fbac4bf3..d5347f937eae 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -291,13 +291,20 @@ - <_MustTrim Condition="'$(_MustTrim)' == '' And '$(RuntimeIdentifier)' != '' And ($(_ProjectType.EndsWith('ExecutableProject')) Or $(_ProjectType.EndsWith('AppExtensionProject'))) And '$(IsMacEnabled)' == 'true'">true - true - <_LinkModeProperty Condition="'$(_PlatformName)' == 'macOS'">LinkMode <_LinkModeProperty Condition="'$(_PlatformName)' != 'macOS'">MtouchLink - + + + + + + + <_MustTrim Condition="'$(_MustTrim)' == '' And '$(RuntimeIdentifier)' != '' And ($(_ProjectType.EndsWith('ExecutableProject')) Or $(_ProjectType.EndsWith('AppExtensionProject'))) And '$(IsMacEnabled)' == 'true'">true + true + + + <_PreviousPublishTrimmedValue>$(PublishTrimmed) diff --git a/tests/dotnet/UnitTests/PublishTrimmedTest.cs b/tests/dotnet/UnitTests/PublishTrimmedTest.cs index f7675e066d2f..7fb47df4c0d1 100644 --- a/tests/dotnet/UnitTests/PublishTrimmedTest.cs +++ b/tests/dotnet/UnitTests/PublishTrimmedTest.cs @@ -2,13 +2,18 @@ namespace Xamarin.Tests { [TestFixture] public class PublishTrimmedTest : TestBaseClass { [Test] - [TestCase (ApplePlatform.iOS, "ios-arm64")] - [TestCase (ApplePlatform.TVOS, "tvos-arm64")] - [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64")] - [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64")] - [TestCase (ApplePlatform.MacOSX, "osx-x64")] - [TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64")] - public void DisableLinker (ApplePlatform platform, string runtimeIdentifiers) + [TestCase (ApplePlatform.iOS, "ios-arm64", "false")] + [TestCase (ApplePlatform.TVOS, "tvos-arm64", "false")] + [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64", "false")] + [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "false")] + [TestCase (ApplePlatform.MacOSX, "osx-x64", "false")] + [TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64", "false")] + + [TestCase (ApplePlatform.iOS, "ios-arm64", "true")] + [TestCase (ApplePlatform.TVOS, "tvos-arm64", "true")] + [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64", "true")] + [TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64", "true")] + public void DisableLinker (ApplePlatform platform, string runtimeIdentifiers, string value) { var project = "MySimpleApp"; Configuration.IgnoreIfIgnoredPlatform (platform); @@ -17,13 +22,12 @@ public void DisableLinker (ApplePlatform platform, string runtimeIdentifiers) var project_path = GetProjectPath (project, platform: platform); Clean (project_path); var properties = GetDefaultProperties (runtimeIdentifiers); - properties ["PublishTrimmed"] = "false"; + properties ["PublishTrimmed"] = value; var rv = DotNet.AssertBuildFailure (project_path, properties); var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray (); - Assert.AreEqual (1, errors.Length, "Error count"); var linkModeName = platform == ApplePlatform.MacOSX ? "LinkMode" : "MtouchLink"; - Assert.AreEqual ($"{platform.AsString ()} projects must build with PublishTrimmed=true. Current value: false. Set '{linkModeName}=None' instead to disable trimming for all assemblies.", errors [0].Message, "Error message"); + AssertErrorMessages (errors, $"{platform.AsString ()} projects do not support setting 'PublishTrimmed' to any value (current value: {value}). Use the '{linkModeName}' property to configure trimming behavior instead."); } } } From bac65fed71689cef91ab44d81a5ea8346f73e80f Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 4 Dec 2025 11:33:12 +0100 Subject: [PATCH 2/7] Update docs. --- docs/building-apps/build-properties.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/building-apps/build-properties.md b/docs/building-apps/build-properties.md index 6aa958278b11..23ffd354f03e 100644 --- a/docs/building-apps/build-properties.md +++ b/docs/building-apps/build-properties.md @@ -1299,6 +1299,12 @@ See [TrimMode](/dotnet/core/deploying/trimming/trimming-options) for a bit more > to `false` - to disable trimming, set `TrimMode=copy` instead (a build error > will be raised if `PublishTrimmed` is set to `false`). +> [!NOTE] +> Due to [a known issue](https://github.com/dotnet/runtime/issues/108269), setting `PublishTrimmed` +> to `true` may cause confusing problems, so the build will report an error if this +> is detected (the solution is to not set `PublishTrimmed` at all). + + The `TrimMode` property is equivalent to the existing [MtouchLink](#mtouchlink) (for iOS, tvOS and Mac Catalyst) and [LinkMode](#linkmode) (for macOS) properties, but the valid properties values From cf99cf9fbc48a6b616de46caee53982c6b20ee0c Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 4 Dec 2025 11:50:32 +0100 Subject: [PATCH 3/7] tweak --- dotnet/targets/Xamarin.Shared.Sdk.targets | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index d5347f937eae..47cecd607046 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -293,11 +293,16 @@ <_LinkModeProperty Condition="'$(_PlatformName)' == 'macOS'">LinkMode <_LinkModeProperty Condition="'$(_PlatformName)' != 'macOS'">MtouchLink + + + <_PublishTrimmedError Condition="'$(_PublishTrimmedError)' == '' And '$(PublishTrimmed)' != 'true'">true + + <_PublishTrimmedError Condition="'$(_PublishTrimmedError)' == '' And '$(PublishTrimmed)' == '' And '$(PublishAot)' != 'true'">true - - - + <_MustTrim Condition="'$(_MustTrim)' == '' And '$(RuntimeIdentifier)' != '' And ($(_ProjectType.EndsWith('ExecutableProject')) Or $(_ProjectType.EndsWith('AppExtensionProject'))) And '$(IsMacEnabled)' == 'true'">true From a016155e2961d78760e8a24a47dcd50f47bbd4c2 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 4 Dec 2025 18:53:16 +0100 Subject: [PATCH 4/7] booleans --- dotnet/targets/Xamarin.Shared.Sdk.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index 47cecd607046..051fce8f08db 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -295,7 +295,7 @@ <_LinkModeProperty Condition="'$(_PlatformName)' != 'macOS'">MtouchLink - <_PublishTrimmedError Condition="'$(_PublishTrimmedError)' == '' And '$(PublishTrimmed)' != 'true'">true + <_PublishTrimmedError Condition="'$(_PublishTrimmedError)' == '' And '$(PublishTrimmed)' != 'true' And '$(PublishTrimmed)' != ''">true From dafc6822716ee9d581e0409cca9eaf1ecee5b3b9 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 5 Dec 2025 15:50:25 +0100 Subject: [PATCH 5/7] Boolean logic... --- dotnet/targets/Xamarin.Shared.Sdk.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index 051fce8f08db..eee240d82f3a 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -299,7 +299,7 @@ - <_PublishTrimmedError Condition="'$(_PublishTrimmedError)' == '' And '$(PublishTrimmed)' == '' And '$(PublishAot)' != 'true'">true + <_PublishTrimmedError Condition="'$(_PublishTrimmedError)' == '' And '$(PublishTrimmed)' != '' And '$(PublishAot)' != 'true'">true From 90b7214167f9151403f88696960e36462f19f61a Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 8 Dec 2025 18:14:54 +0100 Subject: [PATCH 6/7] Update test. --- tests/dotnet/UnitTests/ProjectTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dotnet/UnitTests/ProjectTest.cs b/tests/dotnet/UnitTests/ProjectTest.cs index e5ade9ac2e5f..0046d0eaf68d 100644 --- a/tests/dotnet/UnitTests/ProjectTest.cs +++ b/tests/dotnet/UnitTests/ProjectTest.cs @@ -457,7 +457,7 @@ public void InvalidRuntimeIdentifiers (ApplePlatform platform, string runtimeIde [TestCase (ApplePlatform.iOS, "iossimulator-x64", false)] [TestCase (ApplePlatform.iOS, "ios-arm64", true)] [TestCase (ApplePlatform.iOS, "ios-arm64", true, null, "Release")] - [TestCase (ApplePlatform.iOS, "ios-arm64", true, "PublishTrimmed=true;UseInterpreter=true")] + [TestCase (ApplePlatform.iOS, "ios-arm64", true, "UseInterpreter=true")] [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", false)] [Category ("WindowsInclusive")] public void IsNotMacBuild (ApplePlatform platform, string runtimeIdentifiers, bool isDeviceBuild, string? extraProperties = null, string configuration = "Debug") From c9c64847e6e8341bb0785a5d95259728e5467130 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 8 Dec 2025 18:16:28 +0100 Subject: [PATCH 7/7] Update tests/dotnet/UnitTests/PublishTrimmedTest.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- tests/dotnet/UnitTests/PublishTrimmedTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dotnet/UnitTests/PublishTrimmedTest.cs b/tests/dotnet/UnitTests/PublishTrimmedTest.cs index 7fb47df4c0d1..124c525822ae 100644 --- a/tests/dotnet/UnitTests/PublishTrimmedTest.cs +++ b/tests/dotnet/UnitTests/PublishTrimmedTest.cs @@ -13,7 +13,7 @@ public class PublishTrimmedTest : TestBaseClass { [TestCase (ApplePlatform.TVOS, "tvos-arm64", "true")] [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64", "true")] [TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64", "true")] - public void DisableLinker (ApplePlatform platform, string runtimeIdentifiers, string value) + public void PublishTrimmedNotSupported (ApplePlatform platform, string runtimeIdentifiers, string value) { var project = "MySimpleApp"; Configuration.IgnoreIfIgnoredPlatform (platform);