by gregmac · 5y ago · 0 comments
dotnet publish -r win-x64 -p:PublishSingleFile=true ---self-contained=false
dotnet publish -r linux-x64 -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained=true
To give an example of this for a reasonably complex test tool I have on .NET core 3.1, the Windows exe is 3.7MB and the linux binary is 38MB. I'm guessing there's some room for optimization in the process though, as the linux binary is compressed (tgz) to 13.37MB. -p:Configuration=Release -p:DebuggerSupport=false
FWIW, I did also try the following, but found they had basically no impact on output size: -p:TrimMode=link
-p:EnableUnsafeBinaryFormatterSerialization=false
-p:EnableUnsafeUTF7Encoding=false
-p:EventSourceSupport=false
-p:HttpActivityPropagationSupport=false
(Tested on .NET Core 3.1.5)38MB is a pretty typical size for a real-world, self-contained, assembly-trimmed package, and the size comes from the runtime itself, plus the core assemblies that weren't trimmed out.