Sklivvz
Sklivvz

Reputation: 31133

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

Upvotes: 9

Views: 2444

Answers (2)

avanisagar
avanisagar

Reputation: 101

  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.

Upvotes: 3

J. Doe
J. Doe

Reputation: 2747

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.

Upvotes: 1

Related Questions