S
S
sorax12018-05-03 22:31:22
.NET
sorax1, 2018-05-03 22:31:22

How to compile a .NET Core project under ubuntu into one file?

On .NET Core, a netcoreapp2.0 console application for ubuntu is implemented and the project is built on the same ubuntu.
The project is published by the team
dotnet publish -c release -r ubuntu.16.04-x64
The project is assembled and the finished project with all the necessary libraries and other dependencies is in the publish folder, which can be transferred to any ubuntu server and it will work fine there, but I would like not to miss the entire folder with a bunch of libraries, but just one executable file well, or at least somehow reduce the number of output files.
Is this possible, and if so, how to implement it, what are the ways?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stanislav Silin, 2018-05-03
@byme

There is something like that , but I would say it is not quite right and while it is in a pre-alpha state. The result is one "bold" executable file.
UPD. There is still this , but there will be even more crutches here

A
Alexander Kuznetsov, 2018-05-04
@DarkRaven

In theory, you can build a deb package that will contain your application.
Also, you can look here - https://docs.snapcraft.io/build-snaps/your-first-snap

B
basrach, 2018-05-05
@basrach

This does not only apply to Core under Ubuntu. This also applies to regular .Net under Windows.
This problem is solved by adding all the dependencies of the executable file (for example, .exe) to the resources of this .exe itself. Then, when the application starts, the AppDomain.AssemblyResolve event handler is registered, which retrieves the required assembly from the resources, loads it into the domain, and returns a reference to it to the environment. AppDomain.AssemblyResolve is called every time the application needs a dependency.
It is simple and easy to implement, and it does not take much time.
There are also libraries that are built into the build process and allow you to automate this business. ILMerge has already been mentioned above , there is alsoFody , maybe there are some other analogues.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question