I developed a tool to slim down .NET programs

I developed a tool to slim down .NET programs

I developed a tool to slim down .NET programs, which can delete referenced but unused assemblies. I used it to slim down a .NET Core program from `147 MB` to `59.5 MB`.

Last updated 12/26/2021 9:56 PM
杨中科
2 min read
Category
.NET
Tags
.NET C# Slimming

I developed a tool to slim down .NET applications, which can remove referenced but unused assemblies. I used it to slim a .NET Core application from 147 MB down to 59.5 MB.

When publishing a .NET application, there is a trimming feature for assemblies, but it only performs static checks. For example, suppose our project uses assembly A, which contains two methods M1 and M2. Inside M1, it calls code from assembly B, and inside M2, it calls code from assembly C. If our program only invokes M1 and never M2, .NET trimming cannot remove the unused assembly C that is only called by M2.

My tool performs runtime checks and removes assemblies that are never called at runtime (taking into account dynamic mechanisms like reflection). Furthermore, the built-in trimming feature in .NET does not support WinForms or WPF projects.

The implementation principle of my tool is not complicated, but I searched extensively and couldn't find any similar tool, so I wrote one myself. If anyone knows of such a tool, please let me know. If I confirm that this is my original work, I will polish the tool (testing compatibility with various projects, .NET versions, and operating systems), release it, and open-source it.

If this project is open-sourced, I will announce it on my social media channels. You can follow me on Bilibili, Toutiao, Douyin, Weibo, YouTube, and other platforms. My channel name on all platforms is "杨中科".

Original author: 杨中科

Original link: https://mp.weixin.qq.com/s/B7QdVQWtgBKNKOEFj2Lg4g

Keep Exploring

Related Reading

More Articles