-
Notifications
You must be signed in to change notification settings - Fork 518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dotnet] Embrace trimming. #20354
[dotnet] Embrace trimming. #20354
Conversation
e15f0c2
to
4ecbf59
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
4ecbf59
to
cfed404
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cfed404
to
6f6f62b
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6f6f62b
to
526c00c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This way the trimming analyzers will be enabled for library projects, which will help towards getting all libraries trimmer safe.
6d98da5
to
ef26cb8
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
💻 [CI Build] Windows Integration Tests passed 💻✅ All Windows Integration Tests passed. Pipeline on Agent |
📚 [PR Build] Artifacts 📚Packages generatedView packagesPipeline on Agent |
💻 [PR Build] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [PR Build] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
✅ API diff for current PR / commitLegacy Xamarin (No breaking changes)
NET (empty diffs)
✅ API diff vs stableLegacy Xamarin (No breaking changes).NET (No breaking changes)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🚀 [CI Build] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 172 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
💻 [PR Build] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just go with what we have here for now. Maybe there is no need for TrimMode=link
to work and everyone uses TrimMode=full
.
<_OriginalSuppressTrimAnalysisWarnings>$(SuppressTrimAnalysisWarnings)</_OriginalSuppressTrimAnalysisWarnings> | ||
<SuppressTrimAnalysisWarnings Condition="'$(_UseNativeAot)' == 'true'">true</SuppressTrimAnalysisWarnings> | ||
<!-- Otherwise suppress trimmer warnings unless we're trimming all assemblies --> | ||
<SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == '' And '$(TrimMode)' == 'full'">false</SuppressTrimAnalysisWarnings> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically what is in the Android workload right now, but I noticed you can also use TrimMode=link
:
I wonder if this TrimMode=link
setting is actually wrong? I can't find this in the docs:
And not finding anything in .NET like: <TrimMode Condition="'$(TrimMode)'=='link'">full</TrimMode>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shows up if you select .NET 6
at the top of the page: https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options?pivots=dotnet-6-0#trimming-granularity
Context: dotnet/android#8805 Context: xamarin/xamarin-macios#20354 In .NET 9, we want .NET MAUI applications to be able to use the `TrimMode=full` option to remove unused code from the application: <PropertyGroup Condition="'$(Configuration)' == 'Release'"> <TrimMode>full</TrimMode> </PropertyGroup> With all the trimming work done to support NativeAOT, we should toggle the same options when `TrimMode=full` is used: * `MauiStrictXamlCompilation=true` * `MauiXamlRuntimeParsingSupport=false` * `MauiShellSearchResultsRendererDisplayMemberNameSupported=false` * `MauiQueryPropertyAttributeSupport=false` * `MauiImplicitCastOperatorsUsageViaReflectionSupport=false` With these set, the `dotnet new maui` project template *should* have zero trimmer warnings when `TrimMode=full` is used. Developers can also adjust these settings and respond to trimmer warnings in their own code. I also updated `RunOnAndroid` and `RunOniOS` tests to verify that project templates launch successfully with `TrimMode=full`.
Context: dotnet/android#8805 Context: xamarin/xamarin-macios#20354 In .NET 9, we want .NET MAUI applications to be able to use the `TrimMode=full` option to remove unused code from the application: <PropertyGroup Condition="'$(Configuration)' == 'Release'"> <TrimMode>full</TrimMode> </PropertyGroup> With all the trimming work done to support NativeAOT, we should toggle the same options when `TrimMode=full` is used: * `MauiStrictXamlCompilation=true` * `MauiXamlRuntimeParsingSupport=false` * `MauiShellSearchResultsRendererDisplayMemberNameSupported=false` * `MauiQueryPropertyAttributeSupport=false` * `MauiImplicitCastOperatorsUsageViaReflectionSupport=false` With these set, the `dotnet new maui` project template *should* have zero trimmer warnings when `TrimMode=full` is used. Developers can also adjust these settings and respond to trimmer warnings in their own code. I also updated `RunOnAndroid` and `RunOniOS` tests to verify that project templates launch successfully with `TrimMode=full`.
Context: dotnet/android#8805 Context: xamarin/xamarin-macios#20354 In .NET 9, we want .NET MAUI applications to be able to use the `TrimMode=full` option to remove unused code from the application: <PropertyGroup Condition="'$(Configuration)' == 'Release'"> <TrimMode>full</TrimMode> </PropertyGroup> With all the trimming work done to support NativeAOT, we should toggle the same options when `TrimMode=full` is used: * `MauiStrictXamlCompilation=true` * `MauiXamlRuntimeParsingSupport=false` * `MauiShellSearchResultsRendererDisplayMemberNameSupported=false` * `MauiQueryPropertyAttributeSupport=false` * `MauiImplicitCastOperatorsUsageViaReflectionSupport=false` With these set, the `dotnet new maui` project template *should* have zero trimmer warnings when `TrimMode=full` is used. Developers can also adjust these settings and respond to trimmer warnings in their own code. I also updated `RunOnAndroid` and `RunOniOS` tests to verify that project templates launch successfully with `TrimMode=full`. Note: * Skip `maui-blazor` on iOS for now, as it contains trimmer warnings.
As we have solved all trimming warnings in the our workloads, we can now go
all in on trimming.
Early in .NET 6 we hid many trimming warnings as we did not yet plan to solve
them:
Ref: #10405
These warnings were not actionable at the time for customers, as
many warnings were from our code.
Going forward, let's stop suppressing these warnings if
TrimMode=full
.We can also enable trimming for new projects:
dotnet new ios|tvos|macos|maccatalyst
These will have the
TrimMode
property set toFull
by default forRelease
builds:
We wouldn't want to do this for existing projects, as they might have existing
code, NuGet packages, etc. where trimming warnings might be present.
We can also improve the templates for class libraries and binding libraries:
dotnet new ioslib|iosbinding|tvoslib|tvosbinding|...
This way, new class libraries and binding libraries will be trimmable by
default and be able to react to trimming warnings.
Fixes #10405.
Ref: dotnet/android#8805