Microsoft has been working hard to bring .Net (Core) to Linux so lets explore the fruits of their labor.
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?
First lets go over some things you should have to start this:
- Visual Studio Code (Download Link)
- NPM (Terminal command)
sudo apt-get install npm
- Update NPM version to latest (Terminal command)
sudo npm install -g npm
- Install Node.js (Terminal command)
sudo apt-get install nodejs-legacy
- Install Yeoman (Terminal command)
sudo npm install -g yo
- Install ASP.Net Generator (Terminal command)
sudo npm install -g generator-aspnet
- Install Bower
sudo npm install -g bower
- Install .Net Core SDK
- Some of the Microsoft Yeoman templates now use “old” .Net Core versions. This will fix those dependencies by installing all .Net Core Framework versions.
sudo apt-get install dotnet-dev*
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
Note: If you get this error ” permission denied ‘/home/user/.config/configstore/insight-yo.yml’ You don’t have access to this file. “
Then try this fix (I received this error on Ubuntu 17.04.):
sudo chmod -R 777 ~/.config/".
You should now have a screen like this one:
Lets Choose “Web Application” (down arrow twice) and hit enter.
Now lets choose Bootstrap for our UI framework
Type a name and hit enter (I choose mywebapp again).
At this point we can follow the instructions printed above in green and run our web app.
cd mywebapp dotnet restore
At this point your new web application should be compiled and running locally on port 5000
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:
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: https://mva.microsoft.com/en-US/training-courses/introduction-to-asp-net-mvc-8322 http://www.asp.net/mvc/overview/getting-started
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 video is fun to watch (good humor) and goes over why .Net Core is performing so well and even shows .Net Core code running on a Raspberry Pi!
- This Pluralsight video has a lot of good information but also covers some really basic information like “how to create an html page” that I find hard to watch since I’ve been creating those since I was about 12 years old. Great course for an absolute beginner though and some good .Net Core info if you skip the basics sections.
This post was based largely on this ASP.Net Core tutorial for OSX and modified for Ubuntu.
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.