I am developing a simple, cross-platform .NET application. I need to distribute it as a self-contained deployment as I can't assume if .NET is already installed.
.NET publish for Windows 10 64 bit generates a 64 MB directory. I am pretty sure most of the DLL files are not needed. Is there a way to optimize the distribution so that only the necessary DLL file are kept?
I'm facing the same problem. So far, here's what I found:
Microsoft released a Trim tool that finds unused assemblies and removes them.
With .NET CLI:
dotnet add package Microsoft.Packaging.Tools.Trimming -v 1.1.0-preview1-25818-01
dotnet publish -r win-x64 -c release /p:TrimUnusedDependencies=true
Your application's footprint is now much smaller (normally)
For a better optimization you can use it with ILLinker:
dotnet new nuget
Open nuget.config and add <add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
between <packageSource>
Here is an example of what your nuget.config should look like.
Then execute the following commands:
dotnet add package ILLink.Tasks -v 0.1.4-preview-981901
dotnet add package Microsoft.Packaging.Tools.Trimming -v 1.1.0-preview1-25818-01
dotnet publish -r win-x64 -c release /p:TrimUnusedDependencies=true
Using these two tools I managed to divide the size of my application by three.
Source: Reducing the size of self-contained .NET Core applications
I'm still trying to get better optimization. I want to run my ASP.NET Core application (currently 72 MB) in an embedded system with only 10 MB.
If anyone has found a better optimization, I'm a buyer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With