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 diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index b997fbac4bf3..eee240d82f3a 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -291,13 +291,25 @@ - <_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 + + + <_PublishTrimmedError Condition="'$(_PublishTrimmedError)' == '' And '$(PublishTrimmed)' != 'true' And '$(PublishTrimmed)' != ''">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 + true + + + <_PreviousPublishTrimmedValue>$(PublishTrimmed) 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") diff --git a/tests/dotnet/UnitTests/PublishTrimmedTest.cs b/tests/dotnet/UnitTests/PublishTrimmedTest.cs index f7675e066d2f..124c525822ae 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 PublishTrimmedNotSupported (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."); } } }