PROWAREtech

articles » current » information-technology » linux » setup-and-configure » easily-install-dot-net-app-on-linux

Publish and Install .NET App on Linux ARM/x64

Easily install any .NET application on Linux by doing a self-contained publish, and automatically run the app using the "supervisor" service.

See also: Install ASP.NET Core on Ubuntu Linux and Configure it to Serve a Web Application

Using Visual Studio

If using Visual Studio, the simpliest way to install a .NET app on Linux is to publish it into a folder and then as a "Self-contained" deployment mode.

Choose to target a folder.

Enter the folder.

Then edit the publish settings and choose a deployment mode of Self-contained.

Proceed to publish the files.

Using the .NET CLI (dotnet)

If developing on Linux or just prefer using the .NET Command Line Interface (CLI) then publish with this command:

dotnet publish -r linux-arm -o <OUTPUT_DIRECTORY>

or:

dotnet publish -r linux-x64 -o <OUTPUT_DIRECTORY>

These commands will produce a self-contained distribution for Linux ARM and Linux x64, respectively.

Copy Files to the Linux Host

Use Secure CoPy (SCP) to copy published files from a Windows 10 (or later) machine or a Linux machine to the Linux host.

scp C:\Users\User\Desktop\published-directory user@hostname-or-ip:/path/to/destination

Make sure the destination folder on the Linux host has write permissions and then make sure the executable uploaded to the Linux host has execute permissions. The easiest way to do this is with "chmod 0777":

sudo chmod 0777 /path/to/destination

and:

sudo chmod 0777 /path/to/destination/executable-file

Configure "Supervisor" to Run the Application

Supervisor will automatically run the "app" everytime the machine starts. Issue these commands to install Supervisor:


sudo apt-get update
sudo apt-get install supervisor

Issue these commands to configure Supervisor:


cd /etc/supervisor/conf.d
sudo nano app.conf

Enter these lines into the .conf file:


[program:app]
command=sudo /path/to/destination/executable command-line-arguments
directory=/path/to/destination
autostart=true
autorestart=true
environment=ASPNETCORE_ENVIRONMENT=Production
user=enter-the-username-here
stopsignal=INT

Here is a real-world example of this file:


[program:WebApplication1]
command=sudo /var/www/WebApplication1/WebApplication1
directory=/var/www/WebApplication1
autostart=true
autorestart=true
environment=ASPNETCORE_ENVIRONMENT=Production
user=root
stopsignal=INT

Here is a real-world example of this file on Amazon Web Services (AWS):


[program:WebApplication1]
command=sudo /var/www/WebApplication1/WebApplication1
directory=/var/www/WebApplication1
autostart=true
autorestart=true
environment=ASPNETCORE_ENVIRONMENT=Production
user=ubuntu
stopsignal=INT

To stop the Supervisor service so that new files may be copied over:


sudo service supervisor stop

To start the Supervisor service after having stopped it:


sudo service supervisor start

This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.
CLOSE