Miha Jakovac

Logo

.NET & DevOps Engineer | Cloud Specialist | Team Enabler

My name is Miha and I've been tinkering with computers for some time now. I remember getting Pentium 100 in the late '90s and that's how it all started.

Specialities:

1 February 2022

Build a single executable in .NET 6.0 - update

by Miha J.

A few months ago, I published a blog post where I described how to publish a .NET 5 self-contained single executable application.

I want to update the previous post for .NET 6, which came with a new dotnet publish argument, EnableCompressionInSingleFile. We can use it like this:

dotnet publish My.csproj --configuration Release --framework net6.0 --self-contained True --output Publish --runtime win-x64 --verbosity Normal /property:PublishTrimmed=False /property:PublishSingleFile=True /property:IncludeNativeLibrariesForSelfExtract=True /property:DebugType=None /property:DebugSymbols=False /property:EnableCompressionInSingleFile=True

The trimming of the self-contained assembly is time-consuming so compression might be a good alternative. If you combine both, you can get the perfect file size.

Below are all permutations of trimming and compression:

☒ trimming, ☒ compression - File size of 70 MB

/property:PublishTrimmed=False /property:PublishSingleFile=True /property:IncludeNativeLibrariesForSelfExtract=True /property:DebugType=None /property:DebugSymbols=False /property:EnableCompressionInSingleFile=False

☒ trimming, ☑ compression - File size of 36 MB

/property:PublishTrimmed=False /property:PublishSingleFile=True /property:IncludeNativeLibrariesForSelfExtract=True /property:DebugType=None /property:DebugSymbols=False /property:EnableCompressionInSingleFile=True

☑ Trimming, ☒ compression - File size of 25 MB

/property:PublishTrimmed=True /property:PublishSingleFile=True /property:IncludeNativeLibrariesForSelfExtract=True /property:DebugType=None /property:DebugSymbols=False /property:EnableCompressionInSingleFile=False

☑ Trimming , ☑ compression - File size of 15 MB

/property:PublishTrimmed=True /property:PublishSingleFile=True /property:IncludeNativeLibrariesForSelfExtract=True /property:DebugType=None /property:DebugSymbols=False /property:EnableCompressionInSingleFile=True

Please remember that compressed assembly will take longer to start, so if that is a concern in your application, test it out thoroughly.

tags: net6, - c#