Setting up our .NET Core project

This chapter assumes that you have already installed .NET Core version 3.1 or higher on your machine. First of all, let's start by launching the following command in our console:

dotnet new

The output will appear as follows:

The result of the dotnet new instruction

The preceding output shows all the .NET Core project templates available on the local machine. Each of these has a user-friendly name, a short name, and tags. They are available in C#,  F# and VB; the default is C#.

To create a new template, we'll use the short name. For example, in order to create a console application, we should run the following instruction:

dotnet new console -n HelloWorld

The preceding instruction will create a new project in the current folder, with the following tree structure:

.
├── HelloWorld.csproj
├── Program.cs
└── obj
├── ...

The HelloWorld.csproj file contains all the meta-information about the project. The .NET Core version of the .csproj file is more lightweight compared to the .csproj file in previous versions of the .NET Framework. We'll discuss the new structure of this project file next in this chapter. The Program.cs file is the entry point of the application. 

To build and execute our project, we can run the following commands inside the project folder:

dotnet build
dotnet run

As expected, we obtain the following result:

Hello World!

Unlike old .NET Framework projects, the build and run steps are lightweight processes, and they don't require any additional tools or configurations. In fact, .NET Core is not strictly chained to the development machine like the .NET Framework. Eventually, developers can write code without any other IDEs or code editors. However, for obvious reasons, it is always recommended that you use them to simplify the development process.

It is also essential to note that, once we execute the dotnet build command, the project files will change in the following way:

.
├── HelloWorld.csproj
├── Program.cs
├── bin
│ └── Debug
│ └── netcoreapp3.1
│ ├── ...
└── obj
├── Debug
│ └── netcoreapp3.1
│ ├── ...

The bin/Debug/ folder contains all the app's DLLs. Below that, we can see the netcoreapp3.1 folder, which refers to the current target framework. Therefore, if you build your project using a multi-target approach, you will find a folder for each target framework you specified. Now that we are able to run a simple console app, let's have a closer look at the csproj present in the project.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.22.136