Victor Castro
Victor Castro

Reputation: 1242

Compile into only one independent binary file

I coded a simple program and I compiled it with dotnet publish -c Release -r osx.10.11-x64

It creates a binary file that works well but if I move this file somewhere else without the other files in the same directory, the program can't run:

A fatal error occurred, the required library libhostfxr.dylib could not be found at /Users/me/

Is there any way to make the binary independent? I remember on Windows and with .NET it was possible using ILMerge (but it uses .dll files, and not .dylib)

Upvotes: 3

Views: 2419

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100751

This is not possible at the moment. .NET Core is still a modular system and by deploying a self-contained application, you essentially ship a copy of the entire runtime. While it is possible to use the new linker (in preview) to reduce the size of the managed assemblies (or use ILMerge to merge all managed assemblies), there are still native assets (the .dylib) files that are reference by name in the code.

There is a different runtime project - CoreRT - which aims to create a single native executable by compiling the managed part ahead of time to machine code. This project is still under development.

Upvotes: 1

Related Questions