├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── Program.cs ├── README.md ├── global.json ├── nuget.config └── test.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | bin 3 | obj 4 | _ 5 | Optimize 6 | 7 | publish 8 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to find out which attributes exist for C# debugging 3 | // Use hover for the description of the existing attributes 4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/test.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}", 16 | // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window 17 | "console": "internalConsole", 18 | "stopAtEntry": false, 19 | "internalConsoleOptions": "openOnSessionStart" 20 | }, 21 | { 22 | "name": ".NET Core Attach", 23 | "type": "coreclr", 24 | "request": "attach", 25 | "processId": "${command:pickProcess}" 26 | } 27 | ,] 28 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/test.csproj" 11 | ], 12 | "problemMatcher": "$msCompile" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace test 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IlLinker example 2 | 3 | This is an example of how to minimize the size of a .NET Core application. 4 | Note that it disable CrossGen, so the startup time is slower. 5 | 6 | To compile: 7 | ``` 8 | dotnet publish -c Release -r win-x64 9 | ``` 10 | 11 | # Results for .NET Core 3.1 12 | 13 | In the .NET Core SDK 3.1 this is acomplished by poking an internal MSBuild property. 14 | Ideally there would be a documented way to change these properties. 15 | 16 | These numbers do no include the native executables, which on 17 | Windows X64 are about 16MB. Deleted assemblies are not included in this list. 18 | Some of these native files are related to debugging and couple be excluded to 19 | reduce the size by a few megabytes. 20 | 21 | | |Before linking (B)|After linking (B)|Size decrease| 22 | |------------------------|------------------|-----------------|-------------| 23 | |Total size of assemblies|52,255,016 |1,770,496 |96.61% | 24 | 25 | |Assembly Name |Before linking (B) |After linking (B) |Size decrease| 26 | |-----------------------------------------------------|------------------------|---------------------|-------------| 27 | | test.dll | 4,096 | 3,584 | 12.50% | 28 | | System.Console.dll | 152,440 | 32,768 | 78.50% | 29 | | System.Runtime.InteropServices.dll | 53,112 | 8,192 | 84.58% | 30 | | System.Private.CoreLib.dll | 9,556,040 | 1,725,952 | 81.94% | 31 | 32 | # Results for .NET Core 2.1 33 | 34 | See the `netcore21` branch. 35 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "3.1.300" 4 | } 5 | } -------------------------------------------------------------------------------- /nuget.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | True 7 | 16 | <_ExtraTrimmerArgs>-c Link -u Link 17 | 18 | 19 | 26 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 63 | 65 | 66 | 67 | 68 | --------------------------------------------------------------------------------