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:
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.
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.
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 |