.NET Core framework provides one very useful feature – Self-contained application. You don’t need to install any .net runtime on your computer, you can just copy your application to the target host and run it. Furthermore, you can run it on any platform (Windows, Linux, OSX)!
When you create a self-contained application, after publishing, you will see the whole .net runtime next to your application.
There are some advantages:
- You do not need to have installed .NET Core on a target machine
- You can run applications with different .NET Core versions at the same time
But also, disadvantages:
- Bigger application size (for empty web API project around 50 MB)
- Limited target runtimes list (see list here)
Let’s create simple web API application and deploy it to the clean Ubuntu 14.04 machine!
- Installed .NET Core
- Editor (Visual Studio Code, Visual Studio 2015, Rider, notepad, etc…)
- sftp client (winscp)
- ssh client (putty)
Create empty application
An important part is runtimes section. You can find supported runtimes here: RID catalog
Also, you should not include “type”: “platform” option in the following section
Now, edit Program.cs
public class Program
public static void Main(string args)
var host = new WebHostBuilder()
In this file, we have configured our hosting environment, which is Kestrel (cross-platform web server) and specified which IP and port it will use.
public class Startup
public void ConfigureServices(IServiceCollection services)
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
Here we enabled MVC and Logging in our application.
Now the logic, LuckController.cs
public class LuckController : Controller
public IActionResult Try()
Now let’s restore all required packages. In command line:
And run application
If everything is ok you can go to http://localhost:5000/Luck/Try and you will see 42.
Publish and run application on a remote machine
To create self-contained application run following command:
dotnet publish --configuration Release --runtime ubuntu.14.04-x64
where –runtime value is one of the runtimes elements from project.json
You will see folder where you can find self-contained application
Archive and copy folder to the target machine.
Extract archive, navigate to the extracted folder and make file executable:
chmod +x test
Your first self-contained ASP.NET Core application is ready!
Here is more information about different .NET Core application types