CHAPTER 3
Now that it is clear what ASP.NET Core and .NET Core are, and why they were created, it's time to look at how to install them and how to build a simple application with them.
Installing on Windows is pretty easy. With Visual Studio 2017, chances are you already installed it. If not, go back to the Visual Studio Installer and make sure you have the .NET Core workload selected.

Figure 3-1: Visual Studio Installer
The beauty of .NET Core is that it can also be installed on a Mac (or Linux for that matter) without relying on third-party frameworks, as was needed before with Mono.
Each distribution of Linux has its own individual way of installing, but in the end, the process boils down to the same principles:
You can read instructions specific to your distribution on the official .NET Core website. As an example, we’ll show you how to install on a Mac.
Code Listing 3-1
>brew update |
Once all these pre-requisites have been installed, you can download and install the official SDK for macOS by downloading it from the official official .NET Core website.
On Linux and Mac, you do not have Visual Studio to develop apps, but you can use the .NET Core SDK or Visual Studio Code, which is a lightweight, extensible cross-platform text editor built by Microsoft and the community. The last chapter of this book covers in detail each of the tools with which you can build .NET Core apps.
With so many operating systems and tools available, there are many ways to create a .NET Core application, but all the visual tools rely on the SDK to get things done. Here we are going to build our first .NET Core application using the dotnet core command line interface (CLI).
The main entry point for the SDK is the dotnet command. This command, depending on the verb used, can do lots of things, from acting as host and runner for the application to creating a new project, managing dependencies, and building applications.
As an example, let's create a simple "Hello World" command line application using the dotnet CLI. Since the command line tools are cross-platform, the following steps can be performed on any of the supported systems: Windows, Mac, or Linux.
Open the Command Prompt (or terminal) and create an empty folder, calling it HelloWorldApp. Next, move inside this newly created folder and launch the dotnet new console command.
Now, launch the dotnet restore command to download and install all the packages and finally launch the dotnet run command to build and run the project.
Figure 3-2 shows the output of this sequence of commands.

Figure 3-2: dotnet CLI
Let's dive into what happened here.
The dotnet new console command added two files to the folder:
The Program.cs file is pretty simple, as it just prints the Hello World! string to the console.
Code Listing 3-2
using System; |
What is more interesting to look at is the HelloWorldApp.csproj file. If you’ve ever looked at the project files used by Visual Studio with the full .NET Framework, you might wonder why we even discuss it. You rarely looked inside them, as they were black boxes written in XML. However, with .NET Core, they become easier to modify manually or via other commands of the dotnet tool.
Code Listing 3-3
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
Apart from the MSBuild imports, the file is basically split in three areas:
Another way you can build the same console application is by using Visual Studio. First, go to the new project dialog and select Console Application (.NET Core), as shown in Figure 3-3.

Figure 3-3: New Console Application Using Visual Studio 2017
Once the project has been created, add text to the console application and launch the project. Figure 3-4 shows Visual Studio with the console application loaded.

Figure 3-4: Hello World Application
In this chapter, we've shown why 2016 is one of the few landmarks in our industry, together with 1996 when Microsoft released ASP Classic and 2002 when the .NET Framework and ASP.NET were released.
.NET Core is the next evolution of the Microsoft web development stack. While not as different from the .NET Framework as the .NET Framework was from ASP Classic, it still changes the foundations on which ASP.NET applications are built.
You've also seen how to install .NET Core on Windows, Mac, and Linux, and how to build a simple application using the base layer of .NET tools: the dotnet CLI. With this knowledge, you are ready to explore the new ASP.NET Core application framework.