You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proposal: Support for trimmable (ILLink) assemblies
Summary
Trimming is a great feature introduced with .NET 5, but CsWinRT does not support it. This should be fixed, so assembly sizes can be reduced.
Rationale
Trimming with ILLink provides great results when publishing self contained applications. I have reduced the size of the Microsoft.Windows.SDK.NET assembly by a factor of 45, taking it from 25mb to 0.55mb! I see the same great result in other projected libraries as well.
Since WinUI is using CoreCLR, trimming will be an important tool to keep assemblies small. Same goes for Xamarin apps using the desktop SDK.
Important Notes
Issues I have encountered so far:
Internal constructors, used by internal factories, are incorrectly trimmed.
Missing interfaces and types in the ABI namespace. Perhaps an explicit interface implementation could fix this.
As you can expect, the reflection-based factories in the ABI namespace quickly break, however, these types can manually be preserved by whitelisting them using a TrimmerRootDescriptor.
ILLink can be enabled by specifying the following properties:
Thanks for opening this @trympet. We are aware of some of the issues that you mention and are tracking this with #373 which also has some changes we are considering to address them.
Proposal: Support for trimmable (ILLink) assemblies
Summary
Trimming is a great feature introduced with .NET 5, but CsWinRT does not support it. This should be fixed, so assembly sizes can be reduced.
Rationale
Trimming with ILLink provides great results when publishing self contained applications. I have reduced the size of the Microsoft.Windows.SDK.NET assembly by a factor of
45
, taking it from 25mb to 0.55mb! I see the same great result in other projected libraries as well.Since WinUI is using CoreCLR, trimming will be an important tool to keep assemblies small. Same goes for Xamarin apps using the desktop SDK.
Important Notes
Issues I have encountered so far:
As you can expect, the reflection-based factories in the ABI namespace quickly break, however, these types can manually be preserved by whitelisting them using a
TrimmerRootDescriptor
.ILLink can be enabled by specifying the following properties:
To whitelist the Windows SDK for trimming:
Further reading: https://github.com/mono/linker/blob/main/docs/data-formats.md
The text was updated successfully, but these errors were encountered: