I've created a self-contained .NET Core console application following this good tutorial.
This process produces a /publish
folder with 123(!) files, including my executable. Now, since all these dlls are unlikely to ever change, I'd like to statically link them to the executable and get a single, clean executable.
I'm mostly interested in linking a win64 target on my build server, however instructions on how to build a macosx executable or a linux one are going to be useful to me and to future readers.
I remember doing this under .Net classic a few years back. Has anyone succeeded in doing it under .Net Core?
See also this related corefx issue
Self-contained needs a reference to .Net Core CLI and CoreFX, so you cannot simply create "one DLL" with all. You can try to minimize the amount of DLLs by adding libs function into your main project but I cant recommend this way
It sounds like the feature you want is CoreRT (.NET Native compiler toolchain) but it is still under heavy development and it only works for UWP out of the box.
Right click on the .Net project (not the solution) and go to Publish.
Click on "Show all settings"
Select the required configuration and target framework and target runtime
Keep Deployment mode as self-contained
Go to "File publish options" at the bottom, and select the following options:
i. Produce Single File
ii. Enable ReadyToRun Compilation
Save the settings and publish your project.
This will package all the dlls in the executable itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With