Deploy .NET Core app on Ubuntu

check if it runs

dotnet run

Deploy in a build directory

dotnet publish --output “ /var/www/build” --configuration release

Go to the build directory and run the application

dotnet ForExample.dll

Create the service file

sudo nano /etc/systemd/system/kestrel-ForExample-test.service
[Unit]
Description=Example .NET Web API App running on Ubuntu
[Service]
WorkingDirectory=/var/www/ForExample/ForExample
ExecStart=/usr/bin/dotnet /var/www/build/ForExample.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.t

Register the service

sudo systemctl enable kestrel-ForExample-test.service

Start the service and verify that it’s running.

sudo systemctl start kestrel-mebgispanel-test.service
sudo systemctl status kestrel-mebgispanel-test.service

Check the server logs

sudo journalctl -fu kestrel-helloapp.service

References
https://medium.com/faun/ubuntu-servers-and-asp-net-core-project-deployment-using-nginx-d9a3a1f6ac82