Getting Started with .Net Core MVC in Ubuntu

Microsoft has been working hard to bring .Net (Core) to Linux so lets explore the fruits of their labor.

Why?

Personally I’ve grown fond of C# and  I love that the new Microsoft is embracing Linux and it doesn’t hurt that it’s starting to perform better than the competitors out there like Node.js. I also personally like that C# syntax is close to PHP, which made it easy for me to learn, and that Visual Studio Code/Community “Intellisense” (code autocomplete if you will) makes writing C# fun and relatively easy. Lastly I like the fact that C# is compiled code and not a scripting language and that it can be written into everything from a console application to a Web Application.

Need more reasons?

Prerequisites

First lets go over some things you should have to start this:

  • NPM (Terminal command)
sudo apt-get install npm
  • Update NPM version to latest (Terminal command)
sudo npm install -g npm
  • Visual Studio Code (Download Link)
https://code.visualstudio.com
  • Install Yeoman (Terminal command)
sudo npm install -g yo
  • Install Node.js (Terminal command)
sudo apt-get install nodejs-legacy
  • Install ASP.Net Generator (Terminal command)
sudo npm install -g generator-aspnet
  • Install .Net Core SDK
Instructions: https://www.microsoft.com/net/core

Getting Started

That should cover the pre-requisites needed but if I missed anything please comment below. Now lets start our Web App.

mkdir mywebapp

cd mywebapp

yo aspnet

You should now have a screen like this one:

yo aspnet

Lets Choose “Web Application” (down arrow twice) and hit enter.

bootstrapNow lets choose Bootstrap for our UI framework

webappname

Type a name and hit enter (I choose mywebapp again).

postinstallinstructions

At this point we can follow the instructions printed above in green and run our web app.

dotnetrestore

cd mywebapp

dotnet restore

dotnet run

dotnetrunning

At this point your new web application should be compiled and running locally on port 5000

http://localhost:5000

chromewebapprunning

Visual Studio Code

Now that you have an application framework downloaded and running it’s a great time to fire up Visual Studio Code and take a look at the source code.

So open Visual Studio and go to file -> Open Folder and choose mywebapp/mywebapp under your home folder or wherever you ran mkdir in your terminal earlier. It should look like this:

vscode

From here I’m not going to go over creating an MVC application because that has already been done very well in other places.

For the basics on ASP.Net MVC

I would start here:

The previously suggested videos above are from when I learned MVC on .Net before .Net Core but now that I’m learning more I’m finding that much has changed so I would recommend going here instead:

This post was based largely on this ASP.Net Core tutorial for OSX and modified for Ubuntu.

Thank You

Thanks for reading. If you found any of this useful please share this page and if there’s any questions or comments please add them below and I’ll be happy to respond when I can.

3 thoughts on “Getting Started with .Net Core MVC in Ubuntu

  1. Hi – following your tutorial (with prerequisites) … as I understand it currently (in limited fashion) … I think you need nodejs-legacy to precede Yoeman (Yoeman seems to look for ‘node’ and fails for me unless I first install nodejs-legacy). Ubuntu 16.04 Lts. I’ve already installed Visual Studio Code and .Net Core. Looking like a good tutorial, ta.

Leave a Reply