Creating a .NET Core console app

Let's learn about how to create a .NET Core console application. Here, we will discuss how to create it from the CLI using the dotnet new command.

As we have already seen that the short name for the command-line console application template is console, we will use it to create this type of project. By default, this creates the new project in the current directory with the name of the same directory unless you specify the name.

Let's first create a console application with all default parameters/options. Open a console window and navigate to a directory of your choice. Then, enter the following command to create a console application project:

dotnet new console

In the following demonstration, we create a new folder named Demo in the D:DotNetCore directory path, navigate to that new directory (D:DotNetCoreDemo) in the console window, and then provide the dotnet new console command:

As we have not specified any name explicitly, it will create a project in the context of the current directory. So, you will see Demo.csproj in that directory, with a C# file named Program.cs.

Let's now create another project, but this time, we will specify a name and the language explicitly. Navigate to the DotNetCore directory in the console window and enter the following command:

dotnet new console -lang C# -n "HelloDotNetCore"

This will create a new folder named HelloDotNetCore, which contains a project that has the same name and a Program.cs code file in C#. If you want to build an F# project, then specify the option as -lang F#. This is shown in the following screenshot by specifying the language as C#:

Note that none of the preceding commands have created any solution file for the projects. To create a solution file from a CLI, the dotnet new sln command is used.
..................Content has been hidden....................

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