How to run a .NET Core console application on Linux

C#.Net CoreUbuntu 16.04

C# Problem Overview


I am using Visual Studio 2015 and created a .NET Core console application. After compiling, I have my project DLL file in the debug folder. And if I want to run it on another computer, I have to install .NET on it and then write dotnet myApp.dll in command window (CMD). But I need to run my application without any installations.

I have read that I must publish my application. I do it with the command dotnet publish -c Release. Now in folder release I have a new folder, publish, with myApp.dll and other dll-files and folder runtimes for different systems. For example, in the Ubuntu.16.04-x64 folder I have file System.Security.Cryptography.Native.OpenSsl.so. But how can I run my application without any new installations of .NET or something else?

C# Solutions


Solution 1 - C#

Follow the below steps to run your application:

  1. Publish your application as a self contained application:

     dotnet publish -c release -r ubuntu.16.04-x64 --self-contained
    
  2. Copy the publish folder to the Ubuntu machine

  3. Open the Ubuntu machine terminal (CLI) and go to the project directory

  4. Provide execute permissions:

     chmod 777 ./appname
    
  5. Execute the application

     ./appname
    

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionParusnikView Question on Stackoverflow
Solution 1 - C#Harit KumarView Answer on Stackoverflow