News for hackers. Stuff that matters.
Re:C# 9 top-level programs and target-typed expressions by MikeTheGreat on Tuesday March 30, 2021 @06:31PM (#26641380)
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. :)

Re:C# 9 top-level programs and target-typed expressions by smcl on Tuesday March 30, 2021 @06:38PM (#26641432)
Yes 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-lo...
Re:C# 9 top-level programs and target-typed expressions by pjc50 on Tuesday March 30, 2021 @06:46PM (#26641483)
Yeah, 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-ga... but that's not exactly practical.

Re:C# 9 top-level programs and target-typed expressions by smcl on Wednesday March 31, 2021 @04:07AM (#26644650)
Wow! 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!
Re:C# 9 top-level programs and target-typed expressions by pjc50 on Tuesday March 30, 2021 @06:36PM (#26641419)
You 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.

Re:C# 9 top-level programs and target-typed expressions by benaadams on Tuesday March 30, 2021 @09:49PM (#26642677)
.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)
Re:C# 9 top-level programs and target-typed expressions by uNople on Tuesday March 30, 2021 @07:53PM (#26641995)
Yes, you can use ILMerge to merge all other DLLS into the main exe/dll: https://stackoverflow.com/questions/8077570/how-to-merge-mul...
Re:C# 9 top-level programs and target-typed expressions by oblio on Tuesday March 30, 2021 @06:34PM (#26641406)
> Is it possible to create a single, stand-alone, self-contained .exe?

Yes.

Re:C# 9 top-level programs and target-typed expressions by vborovikov on Wednesday March 31, 2021 @12:02PM (#26648934)
It's possible but along with an .exe you'll get a couple of .dlls. Exe size will be 60+ Mb.