Create you first ASP.NET Core App and host it in a Linux Docker container on Microsoft Azure (Part 1/3)
As most of you are probably already aware of .NET Core is the new lightweight open-source cross-platform development framework built by the .NET team. With .NET Core you can build applications that run on operating systems like Linux, Windows and MacOS as well as on the cloud. This is especially interesting for web applications that you can build with ASP.NET Core.
In this blog post that I will split into 3 parts I would like to show you how easy it is to create your first ASP.NET Core application on the command line, then host it in a Linux based Docker container and then publish this container to Microsoft Azure.
Part 1: Create you first ASP.NET Core Application
Download .NET Core SDK and command line tools for Windows, Linux oder Mac from https://www.microsoft.com/net/core
Open your command line / terminal to create your first ASP.NET Application:
dotnet new -t web
The type web (-t web) will create a ASP.NET Core MVC template web application. You can of course also use just "dotnet new" to create a basic .NET application and add everything necessary for a ASP.NET Core application yourself.
Do a package restore to get all required packages for your template application from NuGet:
dotnet restore
Build and run you application (you can of course just build your application with "dotnet build"):
dotnet run
You can now see your application running locally on https://localhost:5000
Stop your local web server (Ctrl + C on Windows) and publish your application in release configuration:
dotnet publish -c Release
You can check if publishing worked correctly by changing to the "bin\Release\netcoreapp1.1\publish" folder of your project and start your app with "dotnet yourappname.dll". I had to first install Gulp globally on my machine as it is used to build the template application (npm install -g gulp).
In the next blog post we will take our application, build a Docker image with it and host it in a Docker container. You can find Part 2 here.
Links:
- Download .NET Core: https://www.microsoft.com/net/core
- Get started with ASP.NET Core: https://www.asp.net/get-started
- NuGet Package Manager: https://www.nuget.org/
- Docker: https://www.docker.com/
- Microsoft Azure: https://azure.microsoft.com
Comments
- Anonymous
January 19, 2017
Hi, While trying to do 'dotnet publish -c Release' I get the error 'No executable found matching command "npm". I tried to resolve this by executing 'npm install -g gulp'. But I get the error - 'npm' is not recognized as an internal or external command, operable program or batch file. Would you be able to help me with this?I am trying to run this on a Windows 10 machine. Thanks!- Anonymous
August 03, 2017
I am so sorry, but I just found you comment now. I guess you have already solved this. Have you tried installing npm and node manually? https://nodejs.org/en/download/
- Anonymous