5 ms·
Is it possible to create a single, stand-alone, self-contained .exe? (I'm fine with only building for a single platform - Mac/Win/Linux) Needing to run my prog
by MikeTheGreat 6y ago
Is it possible to create a single, stand-alone, self-contained .exe?
(I'm fine with only building for a single platform - Mac/Win/Linux)
Needing to run my programs (which show up as .dll's) using dotnet just feels weird (and it doesn't match my intuition for 'how programs are run' in Windows cmd/etc).
I'd be fine with an .exe that's not self contained but at least I run it like a 'normal' exe. :)
- oblio 6y ago> Is it possible to create a single, stand-alone, self-contained .exe? Yes.
- smcl 6y agoYes that is possible, you can produce an .exe which contains your application's assemblies but relies on the appropriate .NET runtime being present on the user's computer. You can also build a .exe which has the .NET runtime bundled, but it can be quite big. I made a simple program that wrote "Hello World" to the console [1] and it was between 46-78MB: https://blog.mclemon.org/no-this-is-what-peak-hello-world-looks-like https://blog.mclemon.org/no-this-is-what-peak-hello-world-lo...
- pjc50 6y agoYeah, it's not really a "real" native binary. You can get it down to 8kb by jettisoning all comforts: https://medium.com/@MStrehovsky/building-a-self-contained-game-in-c-under-8-kilobytes-74c3cf60ea04 https://medium.com/@MStrehovsky/building-a-self-contained-ga... but that's not exactly practical.
- smcl 6y agoWow! Yeah indeed there's a few impractical steps required to go all the way to 8kb, but trimming down to a couple of MB is definitely a huge improvement. I somehow never looked into CoreRT before, I'm gonna need to do so. Thanks for sharing this!
- pjc50 6y agoYou have to set up "dotnet publish" for the project that makes the executable. It then makes a stub loader "your program.exe" which looks and behaves normally. You can then make it "self contained", which bundles the assemblies for you and transparently unpacks them. You can have different publish profiles for the different targets.
- benaadams 6y ago.NET 5.0 can now create true single file that doesn't need any unpacking on first run (except on Windows where the Jit and GC dlls will live or be unpacked separately; but that should be resolved in .NET 6.0)
- uNople 6y agoYes, you can use ILMerge to merge all other DLLS into the main exe/dll: https://stackoverflow.com/questions/8077570/how-to-merge-multiple-assemblies-into-one https://stackoverflow.com/questions/8077570/how-to-merge-mul...
- vborovikov 6y agoIt's possible but along with an .exe you'll get a couple of .dlls. Exe size will be 60+ Mb.