I am trying to publish a C# .net core console app I made, to a Linux machine running Centos 7 64 bit. Currently, I am publishing the app using the command:dotnet publish -c release -r contos.7-x64
. Unfortunately, it appears as though publishing in this way requires .net core to be installed on the target machine. Is it possible to do this where I do not need to install anything on the machine that I am publishing to?
2
Answers
I found that the issue was that the project was not compiling to core 2. Rather, the project was compiling to version 1. After making this change, the published project was able to run on Centos.
In .NET Core 2.2 you can create a self-contained app (i.e. not requiring .NET Core runtime installed on host machine) with this command
dotnet publish -r centos.7-x64 -c Release --self-contained
. It’ll produce executable and a lot of dependencies.In .NET Core 3 you can compress all dependencies into a single file
dotnet publish -r centos.7-x64 -c Release /p:PublishSingleFile=true
. You can also add flag/p:PublishTrimmed=true
to reduce executable size by tree trimming.More details can be found here and here.