Create a .net core web application on ubuntu in 5 minutes
I have been spending the past few weeks getting familiar with .net core, the latest release of the .net framework from Microsoft. I will be the first to admit that I am totally impressed by it and I am truly excited by this version of the framework.
The world I have been inhabiting over the past 4 or so years has been a world of cross platform applications. Typically developing applications which are designed or at leasts components of applications that are required to run on any mix of operating systems and platforms i.e. Windows. Mac and Linux and Web , Mobile and desktop.
I have always been fan of the .net framework and the Microsoft development tool stack in general but have not always been a huge advocate of the windows operating system. In my opinion it has always been so ironic that Microsoft have always created great development tooling but were always let down by the operating system.
Install .net core and VS Code
I installed the .net core and the super light weight development text editor called VS Code, following the super easy to follow instructions on the Microsoft website. https://www.microsoft.com/net/core.
Create new web project using the terminal
It is really super easy to create a new web project using terminal window and open the new project in vscode afterward.
dotnet new -t web
Running these simple commands will generate necessary boiler plate code required to start working on your next great project.
Although the above approach my generate you a template really quickly. The template itself is somewhat limiting and it pretty much based on the Microsoft MVC template, which is fine but if you would like work on more current technologies or would like to explore other options. There are alternate templates available.
The aspnet core team have made these templates available via the Yeoman generators, which will require the installation of yo and aspnet core yo generators.
You can install
yo via the terminal if you have NPM (Node Package Manager ) . If not I recommend you install node using NVM (node version manager) on ubuntu.
# Install yo globally
npm install -g yo
We can now install the aspnet generators
npm install -g generator-aspnet
Once complete we can now use it to generate our projects
Which will present the a screen and you can make your selection of the type of project you would like to create
Additional Single Page Application Templates
The community has been really busy creating some addtional project starter templates , which include using addtional frameworks like Aurelia etc. Check out Steve Sandersons blog for more information.
These templates are also available by making use of the Yeoman Generator, and are simple to install. However, before we install these templates there is one additional dependency we need to install called
npm install -g webpack
We can now install the generators
npm install -g yo generator-aspnetcore-spa
Once installed we can generate a project using
If you prefer make us of the
dotnet new command to generate a project, you can but it will take an extra bit of configuration and you will need to install
RC4 of the SDK tools
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893
sudo apt-get update
sudo apt-get install dotnet-dev-1.0.0-rc4-004771
Once the install is complete, add the addtional templates
dotnet new --install Microsoft.AspNetCore.SpaTemplates::*
Once complete, you can then try
dotnet new --help which then should display a list of new templates that are available.
Templates Short Name Language Tags
Console Application console [C#], F# Common/Console
Class library classlib [C#], F# Common/Library
Unit Test Project mstest [C#], F# Test/MSTest
xUnit Test Project xunit [C#], F# Test/xUnit
Empty ASP.NET Core Web Application web [C#] Web/Empty
MVC ASP.NET Core Web Application mvc [C#], F# Web/MVC
MVC ASP.NET Core with Angular angular [C#] Web/MVC/SPA
MVC ASP.NET Core with Aurelia aurelia [C#] Web/MVC/SPA
MVC ASP.NET Core with Knockout.js knockout [C#] Web/MVC/SPA
MVC ASP.NET Core with React.js react [C#] Web/MVC/SPA
MVC ASP.NET Core with React.js and Redux reactredux [C#] Web/MVC/SPA
Web API ASP.NET Core Web Application webapi [C#] Web/WebAPI
Solution File sln Solution
With these new templates available you can then generate a new project using
dotnet new [templatename] to generate a new project like
dotnet new angular
A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.
Latest posts by Gary Woodfine (see all)
- Using IHost .net core console applications - August 15, 2018
- Book Review : Code Complete - August 6, 2018
- How to use Configuration API in .net core console application - August 6, 2018