From 8e63b07913377f64857882f5ebaf8d9ceaba0af9 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 21 Mar 2024 13:13:45 +0100 Subject: [PATCH 1/4] [dotnet] Make 'TrimMode=full' the default for release builds in our templates. --- .../maccatalyst/csharp/MacCatalystApp1.csproj | 6 ++++++ .../Microsoft.iOS.Templates/ios-tabbed/iOSTabbedApp1.csproj | 6 ++++++ .../Microsoft.iOS.Templates/ios/csharp/iOSApp1.csproj | 6 ++++++ .../Microsoft.macOS.Templates/macos/csharp/macOSApp1.csproj | 6 ++++++ .../Microsoft.tvOS.Templates/tvos/csharp/tvOSApp1.csproj | 6 ++++++ 5 files changed, 30 insertions(+) diff --git a/dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalyst/csharp/MacCatalystApp1.csproj b/dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalyst/csharp/MacCatalystApp1.csproj index 5aa19cf04895..94b57039fcd4 100644 --- a/dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalyst/csharp/MacCatalystApp1.csproj +++ b/dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalyst/csharp/MacCatalystApp1.csproj @@ -11,6 +11,12 @@ true MacCatalystApp1 minOSVersion + + + full + full diff --git a/dotnet/Templates/Microsoft.iOS.Templates/ios/csharp/iOSApp1.csproj b/dotnet/Templates/Microsoft.iOS.Templates/ios/csharp/iOSApp1.csproj index 0d36a839d48d..f894bc211824 100644 --- a/dotnet/Templates/Microsoft.iOS.Templates/ios/csharp/iOSApp1.csproj +++ b/dotnet/Templates/Microsoft.iOS.Templates/ios/csharp/iOSApp1.csproj @@ -6,5 +6,11 @@ enable true minOSVersion + + + full diff --git a/dotnet/Templates/Microsoft.macOS.Templates/macos/csharp/macOSApp1.csproj b/dotnet/Templates/Microsoft.macOS.Templates/macos/csharp/macOSApp1.csproj index 673970a02b56..a87d57a208ed 100644 --- a/dotnet/Templates/Microsoft.macOS.Templates/macos/csharp/macOSApp1.csproj +++ b/dotnet/Templates/Microsoft.macOS.Templates/macos/csharp/macOSApp1.csproj @@ -6,5 +6,11 @@ enable true minOSVersion + + + full diff --git a/dotnet/Templates/Microsoft.tvOS.Templates/tvos/csharp/tvOSApp1.csproj b/dotnet/Templates/Microsoft.tvOS.Templates/tvos/csharp/tvOSApp1.csproj index 8bffbdd36f06..173bcca565f1 100644 --- a/dotnet/Templates/Microsoft.tvOS.Templates/tvos/csharp/tvOSApp1.csproj +++ b/dotnet/Templates/Microsoft.tvOS.Templates/tvos/csharp/tvOSApp1.csproj @@ -6,5 +6,11 @@ enable true minOSVersion + + + full From 3b82a7da30ad28d711971990af7c36ff7672ea94 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 21 Mar 2024 13:14:23 +0100 Subject: [PATCH 2/4] [dotnet] Change all library templates to set 'IsTrimmable=true'. This way the trimming analyzers will be enabled for library projects, which will help towards getting all libraries trimmer safe. --- .../maccatalystbinding/csharp/MacCatalystBinding1.csproj | 6 ++++++ .../maccatalystlib/csharp/MacCatalystLib1.csproj | 6 ++++++ .../iosbinding/csharp/iOSBinding1.csproj | 6 ++++++ .../Microsoft.iOS.Templates/ioslib/csharp/iOSLib1.csproj | 6 ++++++ .../macosbinding/csharp/macOSBinding1.csproj | 6 ++++++ .../macoslib/csharp/macOSLib1.csproj | 6 ++++++ .../tvosbinding/csharp/tvOSBinding1.csproj | 6 ++++++ .../Microsoft.tvOS.Templates/tvoslib/csharp/tvOSLib1.csproj | 6 ++++++ 8 files changed, 48 insertions(+) diff --git a/dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalystbinding/csharp/MacCatalystBinding1.csproj b/dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalystbinding/csharp/MacCatalystBinding1.csproj index 2e39782bbdcb..b0bb9a5acfe8 100644 --- a/dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalystbinding/csharp/MacCatalystBinding1.csproj +++ b/dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalystbinding/csharp/MacCatalystBinding1.csproj @@ -5,6 +5,12 @@ enable true true + + + true diff --git a/dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalystlib/csharp/MacCatalystLib1.csproj b/dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalystlib/csharp/MacCatalystLib1.csproj index 966cd2c77c9d..5dae695100cf 100644 --- a/dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalystlib/csharp/MacCatalystLib1.csproj +++ b/dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalystlib/csharp/MacCatalystLib1.csproj @@ -4,5 +4,11 @@ MacCatalystLib1 enable true + + + true diff --git a/dotnet/Templates/Microsoft.iOS.Templates/iosbinding/csharp/iOSBinding1.csproj b/dotnet/Templates/Microsoft.iOS.Templates/iosbinding/csharp/iOSBinding1.csproj index f5fb2a162d07..7c8280edeb93 100644 --- a/dotnet/Templates/Microsoft.iOS.Templates/iosbinding/csharp/iOSBinding1.csproj +++ b/dotnet/Templates/Microsoft.iOS.Templates/iosbinding/csharp/iOSBinding1.csproj @@ -5,6 +5,12 @@ enable true true + + + true diff --git a/dotnet/Templates/Microsoft.iOS.Templates/ioslib/csharp/iOSLib1.csproj b/dotnet/Templates/Microsoft.iOS.Templates/ioslib/csharp/iOSLib1.csproj index ba5bfe4e9faf..a77d6526d31f 100644 --- a/dotnet/Templates/Microsoft.iOS.Templates/ioslib/csharp/iOSLib1.csproj +++ b/dotnet/Templates/Microsoft.iOS.Templates/ioslib/csharp/iOSLib1.csproj @@ -4,5 +4,11 @@ iOSLib1 enable true + + + true diff --git a/dotnet/Templates/Microsoft.macOS.Templates/macosbinding/csharp/macOSBinding1.csproj b/dotnet/Templates/Microsoft.macOS.Templates/macosbinding/csharp/macOSBinding1.csproj index 75c094cbb7ff..c9d67d9c6054 100644 --- a/dotnet/Templates/Microsoft.macOS.Templates/macosbinding/csharp/macOSBinding1.csproj +++ b/dotnet/Templates/Microsoft.macOS.Templates/macosbinding/csharp/macOSBinding1.csproj @@ -5,6 +5,12 @@ enable true true + + + true diff --git a/dotnet/Templates/Microsoft.macOS.Templates/macoslib/csharp/macOSLib1.csproj b/dotnet/Templates/Microsoft.macOS.Templates/macoslib/csharp/macOSLib1.csproj index 858a4723ba6b..b59b1054e293 100644 --- a/dotnet/Templates/Microsoft.macOS.Templates/macoslib/csharp/macOSLib1.csproj +++ b/dotnet/Templates/Microsoft.macOS.Templates/macoslib/csharp/macOSLib1.csproj @@ -4,5 +4,11 @@ macOSLib1 enable true + + + true diff --git a/dotnet/Templates/Microsoft.tvOS.Templates/tvosbinding/csharp/tvOSBinding1.csproj b/dotnet/Templates/Microsoft.tvOS.Templates/tvosbinding/csharp/tvOSBinding1.csproj index 99cfa5b053a7..55a8a2e61e7d 100644 --- a/dotnet/Templates/Microsoft.tvOS.Templates/tvosbinding/csharp/tvOSBinding1.csproj +++ b/dotnet/Templates/Microsoft.tvOS.Templates/tvosbinding/csharp/tvOSBinding1.csproj @@ -5,6 +5,12 @@ enable true true + + + true diff --git a/dotnet/Templates/Microsoft.tvOS.Templates/tvoslib/csharp/tvOSLib1.csproj b/dotnet/Templates/Microsoft.tvOS.Templates/tvoslib/csharp/tvOSLib1.csproj index 854e54f739ef..9512a09c27b4 100644 --- a/dotnet/Templates/Microsoft.tvOS.Templates/tvoslib/csharp/tvOSLib1.csproj +++ b/dotnet/Templates/Microsoft.tvOS.Templates/tvoslib/csharp/tvOSLib1.csproj @@ -4,5 +4,11 @@ tvOSLib1 enable true + + + true From ef26cb8973608f90ffff8cc21531d58d0523dbe3 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 21 Mar 2024 13:15:35 +0100 Subject: [PATCH 3/4] [dotnet] Don't suppress trimmer warnings anymore when 'TrimMode=full' is set. --- dotnet/targets/Xamarin.Shared.Sdk.props | 22 +++++++++++++--------- dotnet/targets/Xamarin.Shared.Sdk.targets | 4 ++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.props b/dotnet/targets/Xamarin.Shared.Sdk.props index e2c40248b2b2..ba5b9c0fde4d 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.props +++ b/dotnet/targets/Xamarin.Shared.Sdk.props @@ -40,15 +40,6 @@ false true - - <_OriginalSuppressTrimAnalysisWarnings>$(SuppressTrimAnalysisWarnings) - true - true - $(AfterMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)Microsoft.$(_PlatformName).Sdk.targets @@ -173,6 +164,19 @@ + + + <_OriginalSuppressTrimAnalysisWarnings>$(SuppressTrimAnalysisWarnings) + true + + false + true + + <_RuntimeIdentifierUsesAppHost>false diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index 7db0b60ac8f2..82875388479f 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -526,6 +526,10 @@ true + + false + true + <_CustomLinkerOptionsFile>$([System.IO.Path]::GetFullPath('$(IntermediateOutputPath)custom-linker-options.txt')) <_CustomLinkerOptionsFile Condition="'$(BuildSessionId)' != ''">$(IntermediateOutputPath)custom-linker-options.txt From ce98e3f07fb38fd2bd39d6bef9023f7ecaa7ab7f Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 18 Apr 2024 08:58:56 +0200 Subject: [PATCH 4/4] [dotnet] Disable COM object descriptor support. This is off by default in .NET, but it's turned off in a property group conditioned on "PublishTrimmed = true", which we only set in a target later in the build, thus we don't pick up the default. Fixes: > Trim analysis error IL2026: System.ComponentModel.TypeDescriptor.NodeFor(Object, Boolean): Using member 'System.ComponentModel.TypeDescriptor.ComObjectType.get' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. COM type descriptors are not trim-compatible. --- dotnet/targets/Xamarin.Shared.Sdk.targets | 1 + 1 file changed, 1 insertion(+) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index 82875388479f..9e419e993c92 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -145,6 +145,7 @@ true false + <_ComObjectDescriptorSupport Condition="'$(_ComObjectDescriptorSupport)' == ''">false false