KISS ASP.NET Core on Ubuntu

ASP.NET Core on Ubuntu

Overview

Previous post ASP.NET on Docker on Windows was a try to run a simple web project on docker on windows. Unfortunately I have failed, let’s try to configure ASP.NET Core on Ubuntu instead.

When you start trying to google internet right now, you may get confused easily. There are different runtimes (mono, coreclr), DNX/DNU vs dotnet (CLI), versions of libraries…
So this time I’ll follow the best and only KISS

How to configure ASP.NET Core on Ubuntu KISS way?

Installing

There is not much to describe, I was following steps from this site:

https://docs.asp.net/en/latest/getting-started/installing-on-linux.html

You don’t need to worry about all these ca-certificates-mono thing, it was installed by default.

To install mono-complete, simply type: sudo apt-get install mono-complete.

VSCode

Visual Studio on Linux? Almost, we have VS Code. Follow steps from

http://askubuntu.com/questions/616075/how-to-install-visual-studio-code-on-ubuntu

Now I have opened solution folder in Visual Studio, C# extension needed installation (and restart).

Choosing proper runtime

This is something that starts to be tougher. You may have plenty of options here, but we will run ASP.NET 5.0 Core with .NET Framwork 4.51 (take a look on project.json), so we need mono runtime.

mogluszka@mogluszkaW540:~/Sources/shout/src/shout$ dnvm use 1.0.0-rc1-update1 -r mono
Active Version              Runtime Architecture OperatingSystem Alias
------ -------              ------- ------------ --------------- -----
       1.0.0-rc1-update1    coreclr x64          linux           
  *    1.0.0-rc1-update1    mono                 linux/osx       default

Starting app

Now it should be easy.

$dnu restore
$dnu build
$dnx kestrel
mogluszka@mogluszkaW540:~/Sources/shout/src/shout$ dnx kestrel
Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

Most Common Issues

  • using Microsoft.Framework.DependencyInjection instead of using Microsoft.Extensions.DependencyInjection
  • different runtime used mono vs coreclr; it may produce compilation errors etc
  • project.json – there are many different ones, the one that changed my world is below

 

{
  "webroot": "wwwroot",
  "version": "1.0.0-*",

  "dependencies": {    
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-*"
  },

  "commands": {
    "kestrel": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": { }    
  },

  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],
  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ]
}

GitHub: ASP 5.0 on Ubuntu

4 thoughts on “KISS ASP.NET Core on Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *