Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I link a .NET Core self-contained deployment?

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

like image 356
Sklivvz Avatar asked Mar 14 '17 10:03

Sklivvz


2 Answers

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.

like image 156
J. Doe Avatar answered Oct 20 '22 01:10

J. Doe


  1. Right click on the .Net project (not the solution) and go to Publish.

  2. Click on "Show all settings"

  3. Select the required configuration and target framework and target runtime

  4. Keep Deployment mode as self-contained

  5. Go to "File publish options" at the bottom, and select the following options:

    i. Produce Single File

    ii. Enable ReadyToRun Compilation

  6. Save the settings and publish your project.

This will package all the dlls in the executable itself.

like image 21
avanisagar Avatar answered Oct 20 '22 01:10

avanisagar