Reduce File Size
I have a very simple console application written in C#, barely more than a couple megabytes. When I publish my project to a self-contained single-file executable, the file comes out to about 50mb.
What's the easiest way to remove unused dependencies and only publish with what it needs?
11 Replies
I understand my file needs more than just my file to run, but 50mb doesn't seem right, idk
I only have one external library imported and that's only 600kb
selfcontained, means it adds everything it needs to run. this includes a shitton of dlls of dotnet..
make it not selfcontained and it will be small but will require that dotnet is installed on target machine
Ohh ok, this makes sense
I will try that, ty
add
<PublishTrimmed>true</PublishTrimmed>
to PropertyGroup section in csproj
you can also use a CLI flag when doing publish -p:PublishTrimmed=true
some things are not compatible with trimming however so don't ignore the warnings it gives you if anywow ty. That cut it down significantly
does it give you warnings?
Only one. But iI can't actually see what the warning is. Maybe I'm blind o.O
Assembly 'FluorineFx.Client' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
In the logs, I only have warnings about potential null referencesyeah, that's not very good - but if it works for you, you may be able to ignore these
It seems to work. I mean it runs... lol
We'll see later when I have more written
basically trimming analyzes your program to remove any unreferenced type and symbol
some things use unbound reflection and other APIs which the trimmer can't see through
that's what causes warnings
sometimes it's obscure parts of code which you don't use so who cares
sometimes it's something you need which causes it to crash (the exception is fairly informative though)
Interesting. Ty for the info