Running a self-contained ASP.NET Core application on Ubuntu
Answer
Now, how do I run my application? My understanding is that because it is a self-contained .NET Core application I do not need to download and install .NET Core anything. My application should contain everything it needs.
You are correct. Run the executable.
When you create a self-contained app, the publish output "contains the complete set of files (both your app files and all .NET Core files) needed to launch your app." That includes the executable.
Example Self-Contained Deployment
Here is the output of dotnet publish -c release -r ubuntu.14.04-x64
for a simple self-contained application. Copy the publish directory to Ubuntu and run the executable.
C:\MyApp\bin\release\netcoreapp1.0\ubuntu.14.04-x64\publish\
...
libsos.so
libsosplugin.so
libuv.so
Microsoft.CodeAnalysis.CSharp.dll
Microsoft.CodeAnalysis.dll
Microsoft.CodeAnalysis.VisualBasic.dll
Microsoft.CSharp.dll
Microsoft.VisualBasic.dll
Microsoft.Win32.Primitives.dll
Microsoft.Win32.Registry.dll
mscorlib.dll
mscorlib.ni.dll
MyApp <------- On Ubuntu, run this executable
MyApp.deps.json and you will see Hello World!
MyApp.dll
MyApp.pdb
MyApp.runtimeconfig.json
sosdocsunix.txt
System.AppContext.dll
System.Buffers.dll
System.Collections.Concurrent.dll
System.Collections.dll
...
C:\MyApp\project.json
{
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": "1.0.1"
}
}
},
"runtimes": {
"ubuntu.14.04-x64" : {},
"win10-x64" : {}
}
}
C:\MyApp\Program.cs
public class Program
{
public static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
}
}
See Also
This document differentiates between framework-dependent and self-contained deployments.
Follow the below steps to run your application:
Publish your application as a self contained application:
dotnet publish -c release -r ubuntu.16.04-x64 --self-contained
Copy the
publish
folder to the Ubuntu machineOpen the Ubuntu machine terminal (CLI) and go to the project directory
Provide execute permissions:
chmod 777 ./appname
Execute the application
./appname
Author: Harit Kumar
Original answer here: How to run a .NET Core console application on Linux