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
UnemployedNinja
UnemployedNinja4mo ago
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
ACiDCA7
ACiDCA74mo ago
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
UnemployedNinja
UnemployedNinja4mo ago
Ohh ok, this makes sense I will try that, ty
abyssptr
abyssptr4mo ago
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 any
UnemployedNinja
UnemployedNinja4mo ago
wow ty. That cut it down significantly
abyssptr
abyssptr4mo ago
does it give you warnings?
UnemployedNinja
UnemployedNinja4mo ago
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 references
abyssptr
abyssptr4mo ago
yeah, that's not very good - but if it works for you, you may be able to ignore these
UnemployedNinja
UnemployedNinja4mo ago
It seems to work. I mean it runs... lol We'll see later when I have more written
abyssptr
abyssptr4mo ago
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)
UnemployedNinja
UnemployedNinja4mo ago
Interesting. Ty for the info