Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a .NET Core console application on Linux [duplicate]

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?

like image 761
Parusnik Avatar asked Oct 20 '17 06:10

Parusnik


People also ask

How do I run a .NET core console app?

In . NET Core, it runs from the dll, so you have to just run the application by running the command prompt and using the command - dotnet run. Open your command prompt and go to that folder where your application persists.

Can we run .NET application on Linux?

NET works well on their Linux distributions. Support is provided by those distributions. You can still open issues at dotnet/core if you run into problems.


1 Answers

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 
like image 150
Harit Kumar Avatar answered Sep 20 '22 13:09

Harit Kumar