Publishing .Net Core application in Linux

7.7k Views Asked by At

I have a .Net Core 5 and i want to publish this application in Linux machine.

I installed .net core 5 sdk in this machine.

I used dotnet publish AppName.sln but i get the " restoring packages " message and it stops at this point. I do not get the publish dirctory or the error messages to figure out what could be the cause of this problem.

am I missing requirements for running .net core application?

1

There are 1 best solutions below

1
On

@M.peace When I deploy to Linux, I publish the application on Windows and copy the files to (deploy to) the Linux system. I never publish on Linux. I only deploy to Linux. That's an important distinction. Here are portions of my deployment action plan:

On the Linux system: (For me, Debian. If you're not using Debian, this may vary.)

Install snapd
    (https://snapcraft.io/docs/installing-snap-on-debian)
    sudo apt-get install snapd
    sudo snap install core
Install .NET 5 Core SDK
    (https://learn.microsoft.com/en-us/dotnet/core/install/linux-snap)
    sudo snap install dotnet-sdk --classic --channel=5.0
    sudo snap alias dotnet-sdk-50.dotnet dotnet
    sudo ln -s /snap/dotnet-sdk/current/dotnet /usr/local/bin/dotnet

Then, the Windows build machine:

Publish Application
    Target Runtime = linux-x64
    Deployment Mode = Framework-dependent
    Zip publish folder and copy to host

My publish settings are:

Visual Studio .NET Core Web App Publish Settings

That is all you need to do to get a built .NET Core project onto Linux. For there, you need to configure it to run. How to do that depends on whether the project is a web app or a console app. Console apps are relatively straight forward. Just run it using dotnet project.dll. Web apps require configuration of Apache and Kestrel.