NET Core program slimmer released, compressing program size to 1/3

NET Core program slimmer released, compressing program size to 1/3

NET Core has the function of "clipping unused code", but since it is implemented using static analysis, its clipping effect is not optimal.

最后更新 3/10/2022 1:12 PM
杨中科
预计阅读 2 分钟
分类
.NET
标签
.NET C# .NET Core clipping slimming

NET Core has the function of "clipping unused code", but since it is implemented using static analysis, its clipping effect is not optimal. It has the following two shortcomings:

  1. Windows Forms and WPF are not supported, and the ones who have the strongest need for program tailoring functions are actually developers of desktop programs.

  2. Unable to delete assemblies that were not in use at runtime. For example, our program uses Assembly A, which in turn references Assembly B and Assembly C. In Assembly A, only Method M1 uses Assembly B, and in Assembly A, only Method M2 uses Assembly C. Our program only calls the M1 method in A, and never calls the M2 method in A. Although the C assembly has not been called by us, the C assembly is still not clipped because the Clip Unused Code feature only does static reference checking.

  3. Does not support reflexes well. Because it is implemented using static analysis, it may prune assemblies that are loaded through reflection at runtime.

因此我开发了一个用来对.NET Core 程序进行瘦身的应用程序,它则可以解决上面提到的.NET Core 的【剪裁未使用的代码】问题,它支持Windows Forms和WPF ,它会在运行时分析程序加载的程序集,从而得知哪些程序集没有被使用,因此它不仅 能删掉更多没有被使用的程序集,而且能天然地 支持反射

Comparison of program tailoring effects:

Original size NET built-in tailoring Zack.DotNetTrimmer
Empty Core MVC project 97MB 50.3MB 43.6MB
Empty WebAPI project 93MB 46.3MB 34.5 MB
Empty WPF project 152 MB not support 75.2 MB
Empty WinForms project 152 MB not support 50.0 MB

项目开源地址:https://github.com/yangzhongke/Zack.DotNetTrimmer/

Keep Exploring

延伸阅读

更多文章
同分类 / 同标签 4/22/2026

Support for. NET by operating system versions (250707 update)

Use virtual machines and test machines to test the support of each version of the operating system for. NET. After installing the operating system, it is passed by measuring the corresponding running time of the installation and being able to run the Stardust Agent.

继续阅读
同分类 / 同标签 2/7/2026

Summary of experience in using AOT

From the very beginning of project creation, you should develop a good habit of conducting AOT release testing in a timely manner whenever new features are added or newer syntax is used.

继续阅读