I have a simple .net core app and publish it by following command:
dotnet publish -c Release -r win10-x64
SqlLocalDbStarter.csproj
Before .NET Core 3.0
dotnet publish -r win-x64 -c Release --self-contained
Pretty self explanatory:
So this works right, we end up with a folder that has our exe and everything that is required to run it, but the issue is that there is a tonne required to run even a HelloWorld console app.
After .NET Core 3.0
dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true
All this does is runs our publish command but tells it to package it within a single file. You’ll notice that we no longer specify the self-contained flag. That’s because it’s assumed that if you are packaging as a single exe, that you will want all it’s dependencies along with it. Makes sense.
A single tidy exe! When this is executed, the dependencies are extracted to a temporary directory and then everything is ran from there. It’s essentially a zip of our previous publish folder! I’ve had a few plays around with it and honestly, it just works. There is nothing more to say about it. It just works.
File Size And Startup Cost
Modify the csproj and add PublishTrimmed = true.
Exe
netcoreapp3.0
true
Now run the below command:
dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true
Reference: