ASP.NET Core 2.x - Getting Started



ASP.NET Core is a cross-platform, high-performance, open source framework for building modern, cloud-based, Internet-connected applications.  It all sums up to:
  1. ASP.NET Core can be used to build web apps and services, IoT apps, and mobile backends.
  2. You can develop it on any OS, say Windows, Linux or MacOS
  3. You can deploy the code on the cloud, be it AWS or Azure or Google Cloud or any local server. 
  4. In the new ASP.NET Core, you have the choice to chose between full blown .NET framework or .NET Core
ASP.NET Core vs ASP.NET

When you get started with ASP.NET Core, the question that comes to your mind is what is so different about it? Well, a lot has changed.

ASP.NET Core can be used to build web applications on Windows, macOS, or Linux. This is truly open source and cross platform. You can even go ahead and use it in command line with any text editor (I prefer Visual Studio Code because of its cool features).
ASP.NET 4.X is a well tested and mature framework that provides the services needed to build enterprise-grade, server-based web apps only on Windows.


ASP.NET Core ASP.NET 4.x
Build for Windows, MacOS, or Linux Build for Windows
Razor Pages is the recommended approach to create a Web UI as of ASP.NET Core 2.x. See also MVC, Web API, and SignalR. Use Web Forms, SignalR, MVC, Web API, WebHooks, or Web Pages
Multiple versions per machine One version per machine
Develop with Visual Studio, Visual Studio for Mac, or Visual Studio Code using C# or F# Develop with Visual Studio using C#, VB, or F#
Higher performance than ASP.NET 4.x Good performance
Choose .NET Framework or .NET Core runtime Use .NET Framework runtime

 When to chose .NET Core?
  • You have cross-platform needs.
  • You are targeting microservices.
  • You are using Docker containers.
  • You need high-performance and scalable systems.
  • You need side-by-side .NET versions per application.
When to chose .NET Framework?
  • Your app currently uses .NET Framework (recommendation is to extend instead of migrating).
  • Your app uses third-party .NET libraries or NuGet packages not available for .NET Core.
  • Your app uses .NET technologies that aren't available for .NET Core.
  • Your app uses a platform that doesn’t support .NET Core.


 Lets get started


In this tutorial you will learn to:

  1. Installing the prerequisite SDK
  2. Using .NET CLI
  3. Creating a new project
  4. Running the new project

1. Installing the prerequisite SDK

Before we get started make sure that .NET 2.2 SDK is installed.
At the time of this writing .NET Core 3.0.0 is in Preview 5. I will be using 2.2 SDK in rest of this tutorial.
Once you click on .NET Core downloads, select 2.2.5 version and install the downloaded file. Once that done, step 1 is complete. Let us proceed to step 2.


2. Using .NET CLI

The .NET Core command-line interface (CLI) is a new cross-platform toolchain for developing .NET applications. 
For 2.2 Version, we can use the following commands:





Basic commands
Project modification commands
Advanced commands
 


3. Creating a new project

At the time of writing the CLI provides the following ways to create a new project:



In this tutorial we are focussing on ASP.NET Core Web App. Open a command shell, and enter the following command:
dotnet new webapp -o aspnetcoreapp
 
 
 Once that done, the terminal should look something like this
Once the task is complete, the terminal should look like

Congratulations 🎉🎉🎉🎉 You have created you first ASP.NET Core project.

4. Running the project
 
I prefer to use Visual Studio Code. This is a very light weight editor packed with powerful features. I use the same editor to code JavaScript, TypeScript, Python and C#. It is amazing and will be a great tool if you don't want to install the all powerful Visual Studio IDE.
Open the project folder using the code editor. By default the CLI will scaffold a nice workable project structure. To know more about this project structure, you can read this blog post
 
 
 
Use the following command to run the application


dotnet run
 
Once you see the command run, the app will start. You can browse the app at https://localhost:5001.
 
 
5. Making changes to the code 
 
Open Pages/Index.cshtml and lets change the <p> tag to ".NET Core is the future" as shown below
 
 
 
Visit https://localhost:5001, and you can see the changes being reflected.
 
Congratulations. You have successfully created, ran and changed a new ASP.NET Core 2.x web app.
 
You see how easy that was. ASP.NET Core can be fun and it has a steep learning curve.

Comments