• Stars
    star
    316
  • Rank 132,587 (Top 3 %)
  • Language
    C#
  • License
    GNU General Publi...
  • Created almost 3 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Zack.DotNetTrimmer

中文文档(Chinese Version)

This application can be used for trimming .NET Core applications. Although .NET Core has the capability of tailoring unused code, however, because it is implemented using static analysis, its tailoring is not optimal. It has the following two disadvantages:

  1. It doesn't support Windows Forms or WPF, and it's desktop developers who are most eager to tailor applications.
  2. It cannot delete assemblies that are not being used at runtime. For example, our program uses assembly A, which in turn references two assemblies B and C. Only method M1 in assembly A uses assembly B, and only method M2 in assembly A uses assembly C. Our program only calls M1 in A, but never M2 in A. Although the C assembly has not been called, the 'tailoring unused code' function does static reference checking, so the C assembly will not be removed.
  3. It doesn't support reflection very well. Because it is implemented using static analysis, it may remove assemblies that would only be loaded by reflection at runtime.

In contrast, Zack.DotNetTrimmer supports Windows Forms and WPF. It analyzes the assemblies loaded by an application at runtime to check which assemblies are not being used, so it not only deletes more assemblies that are not being used, but also naturally ** supports reflection ** . Every advantage has its disadvantage, the downside of Zack.dotnetTrimmer is that it requires you to run the project to be trimmed and run through all the functionality in the program so that you can detect assemblies that will not be used under any circumstances.

Comparison of trimming:

original size .NET Core Zack.DotNetTrimmer
Empty Core MVC Project 97MB 50.3MB 43.6MB
Empty WebAPI Project 93MB 46.3MB 34.5 MB
Empty Empty WPF Project 152 MB Unsupported 75.2 MB
Empty WinForms Project 152 MB Unsupported 50.0 MB

How to:

  1. Download the Zack.DotNetTrimmer executable and unzip the program to disk, Download

  2. Publish the project to be trimmed, please use the self-contained as deployment mode . Do not select Produce single file or 'Framework-dependent' deployment mode.

  3. Run DotNetTrimmer on the command line and pass the full path of the program to be trimmed as the parameter of --file. For example:

Zack.DotNetTrimmer.exe --file d:\a\ASPNETCore6WebAPI1.exe

After running, Zack.DotNetTrimmer will start as a console program, and the program to be trimmed will start automatically.

Note: If the full path contains special characters such as Spaces, please enclose them in double quotation marks, for example: --file "d:/a b/1.exe"

  1. Execute all functions in the program to be trimmed, covering all code paths. After completing all functions, press Ctrl+C or Ctrl+Break in the Zack.DotNetTrimmer console to send a shutdown request for the program to be trimmed. Zack.DotNetTrimmer analyzes and trim the program . When trimming is complete, "Timming done." will be shown.

So the program is clipped. As shown below:

Result

Advanced usage:

1) How do I pass command-line arguments to the program to be trimmed?

Please append them to the end of other arguments. For example:

Zack.DotNetTrimmer.exe --file d:\a\ASPNETCore6WebAPI1.exe --urls=http://localhost:8888/

2) How to restore the deleted files?

Before it exits, it will prompt the backup path, please go to that path to get the backup version.

3) Can I reduce the file size further?

This program uses DiagnosticsClient to check all the assemblies loaded at runtime, so that it knows which assemblies are not being used. By default, only unused assemblies are deleted.

If the --greedy parameter is used, the program also clear the method bodies of unsed classes in the used assemblies, further reducing the file size.

Usage:

Zack.DotNetTrimmer.exe --greedy --file d:\a\ASPNETCore6WebAPI1.exe

However, this requires a more thorough test of all the running paths of the program, or it may cause the program to crash when it runs on something that is not being tested.

4)Can a program run multiple times before it's trimmed?

By default, this program will trim the program as soon as the clipped program exits. On more complex projects, however, you may need to run the program multiple times in different environments to cover the entire path of the code before trimming it.

The program supports two modes: Record and Apply. In Record mode, the program will record the running information of the program to a JSON file. If the JSON file already exists, the program will append the information to the JSON file.

After we run the program to be trimmed in Record mode for many times, we run the program with the Apply model again and specify the JSON file recorded previously. The program will trim the program according to the recorded JSON file.

Record mode uses --record parameter to enable, and need to take the JSON file path as the parameter value, for example:

--record d:/1.json --file d:/1.exe

Apply mode uses --apply parameter to enable, and need to take the JSON file path as the parameter value, for example:

--apply d:/1.json --file d:/1.exe

In Apply mode, we can still use the --greedy parameter.

5)Can I record information about the program to be trimmed and repeat the trimming in an automated build multiple times?

Yes. Please use the --record mode mentioned above, then reuse the recorded JSON file with --apply during building.

6) How it works?

Please check the post out: https://yangzhongke8.medium.com/two-steps-to-builder-a-net-trimmer-application-a3c392757b66

More Repositories

1

NETBookMaterials

C#
533
star
2

Zack.EFCore.Batch

Deleting or Updating multiple records from a LINQ Query in a SQL statement without loading entities
C#
511
star
3

yzk18

Java libraries for beginners. It can simplify the use of Java in the field of office automation.
Java
100
star
4

Zack.AnyDBConfigProvider

ConfigurationProvider for loading configuration from any database, including but not limited to SQLServer, MySQL, Oracle, etc.
C#
89
star
5

RuPengMessageHub

.Net Chat Server Hub
JavaScript
86
star
6

Zack.OpenCVSharp.Ext

It is an extension library of OpenCvSharp. It provides ResourceTracker, which can facilitate the resources management of Mat and other unmanaged resources. It also provide a class, named np, which is a managed version of Numpy.
C#
67
star
7

RuPeng.HystrixCore

C#
48
star
8

RuPeng.RestTemplateCore

C#
32
star
9

LessCode.EFCore.StronglyTypedId

Automatically generate Types for Strongly Typed Id in Entity Framework Core
C#
30
star
10

cownewsql

Sql dialect translator
Java
20
star
11

PhoneAsPrompter

Use for your as a free teleprompter, which can connect to PowerPoint.
C#
19
star
12

YouZack.FromJsonBody

Bind simple parameter of Action with HttpBody of Json format. For ASP.Net Core MVC and ASP.Net Core WebAPI
C#
18
star
13

ApplyMasksForWorldCup

C#
16
star
14

WebCSC

A library that can compile and run C# code in the browser.
C#
16
star
15

CaptchaGen.NetCore

Captcha generator for .net core
C#
15
star
16

MDictExtractor

Extract data from MDict mdd mdx file,like mdict parser
C#
14
star
17

2021NETConf_SourceGenerator

C#
13
star
18

UpYun.NETCore

又拍云 SDK .net Core版
C#
13
star
19

NAHA

NAHA-A python console UI Library that wrapped PyCurses
Python
12
star
20

Zack.TuyaNet

C#
10
star
21

ZackData.Net

A wrapper of EntityFramework/EntityFramework Core, which is like Spring Data JPA
C#
8
star
22

Zack.CameraLib

List connected cameras. CameraPlayer.
C#
8
star
23

XimalayaDownloader

自动化下载喜马拉雅的音频
C#
7
star
24

Microsoft.AspNetCore.Identity.zh-Hans

Chinese version of IdentityError of asp.net core identity. 此程序包包含 ASP.NET Core Identity 的简体中文附属程序集。
C#
7
star
25

rongim.server.netcore

融云ServerSDK .Net Core版
C#
6
star
26

NetAutoGUI

.NET version of pyAutoGUI
C#
6
star
27

BiLiBiLiPaiLou

给B站评论排楼号
JavaScript
6
star
28

uniapp-youzack-components

youzack的UniApp的组件
Vue
5
star
29

GTK4J

Java binding for GTK
Java
5
star
30

Zack.ComObjectHelpers

Utilities for simplifying the operations on ComObject of .NET5.
C#
5
star
31

Windows-Phone-Emulator

C#
5
star
32

Zack.Weixin.MiniProgram

微信小程序服务器端API的.NET版,.NET Standard 2.0。不像Senparc那么复杂
C#
5
star
33

programming_vocabulary

4
star
34

RuPengStudy-NetIM

A Chat window client
JavaScript
4
star
35

NAHAIDE

Java
3
star
36

SweetHeartPlayer

Just for fun
JavaScript
3
star
37

RuPeng.Common.NetCore

Common .net library of Rupeng.Com
C#
3
star
38

YouZack.ErrorMail

Mail Logging provider on .Net Core, which can be configured as 'send the same error only once'
C#
2
star
39

aliyun_yunkaifapingtai_demo

阿里云云开发平台演示案例
Java
2
star
40

Zack.IoT.NET

Python
2
star
41

YZKGame.NET

YZKGame 2D game engine
C#
2
star
42

yzk18.com

sourcecode of yzk18.com websites
HTML
2
star
43

ZackOLEContainer

C#
2
star
44

misc

misc
C
1
star