Chapter 3. Diving into the “Hello World” Application

In Chapter 1, we installed .NET and easily created, built, and ran the “Hello World” application. Let’s take a look at what happened when we built and ran our “Hello World” application (although you and I both know you’ve already looked inside all the generated files).

Associated source code

The source code can be found in the /NetOnLinuxBook/HelloWorld/.

We started by running the dotnet new command. Confession time: in fact, we skipped a command. After running dotnet restore, you can run the dotnet build command to build the binary output. We skipped it in the interest of brevity, and in fact when you execute dotnet run, the command will check to see if a new build is required and run the build automatically. We’ll cover dotnet build later in this chapter.

The dotnet new Command

The dotnet new command will create a new .NET project with the minimum amount of code and associated files necessary to run the application. When run without any additional options, it will create the “Hello World” console application. In this case, two files are created—Program.cs and project.json:

$ ls -altr
total 8
-rwxrw-r--. 1 vagrant vagrant 348 Jun 15 14:43 project.json
-rwxrw-r--. 1 vagrant vagrant 202 Jun 15 14:43 Program.cs
drwxrwxr-x. 3 vagrant vagrant  23 Jul  8 11:24 ..
drwxrwxr-x. 2 vagrant vagrant  42 Jul  8 11:25 .

Program.cs is the program, and it’s short and sweet:

using System;
namespace ConsoleApplication
{
	public class Program ...

Get Transitioning to .NET Core on Red Hat Enterprise Linux now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.