You can check this course on my website.
Typically, you can use Visual Studio or other IDEs to create programs. IDE simplifies development and other processes of creating program, hiding under the hood .NET Command Line Interface (CLI) to manage application.
.NET CLI — is a cross-platform tool for building, creating, running, restoring packages and publishing .NET applications. In fact, you can create programs using only .NET CLI.
Basic .NET CLI Commands
All commands start with dotnet, after dotnet keyword we need to specify necessary command, arguments and options.
dotnet <command> <argument> <option>
List of basic commands:
- new — create a new project or solution based on the specified template;
- build — builds project;
- run — runs source code without any explicit compile;
- restore — restores all project dependencies;
- test — runs unit-tests;
- pack — packs the code into a NuGet package;
- public — prepares the application for deployment;
- help — display documentation for the specified command;
All commands (basic, project modification, advanced, tool management) you can find here — .NET CLI commands.
Create project via .NET CLI
Let’s try to create an application using the .NET CLI. If you have installed .NET then you should already have the CLI.
First, we need to make sure .NET CLI is on our computer. Open a command prompt in Windows (or a console of another OS if you are not on Windows) and enter ‘dotnet’, then press enter and you should see result as below.
Choose or create a folder where you will create a project, I have created D:\Project folder. Open a command line and use the cd command to navigate to the desired folder.
cd D:\Project
To create a project in the .NET CLI use the ‘dotnet new’ command, which is passed the type of the project.
dotnet new console
After that you should see these file:
Now, we can run it in console via next command:
dotnet run
After compilation, the application (.exe) can be found on the hard disk in the project folder in the bin\Debug\net6.0 directory. It will be named like the name of the project and application can be ported to other platforms where .NET 6 is installed.
As you may notice, project name is the same as project folder. To change it we can create new project via next command:
dotnet new console -n MyCustomName
If you need add packages to your project, you can use:
dotnet add package Newtonsoft.json
Instead of Newtonsoft.json you can specify library that you need.
Previous article -> 1.4 Debugging
Next article -> 1.6 C# keywords
Join to our community in Telegram — https://t.me/itifico
If you want to support me, you can buy me a cup of coffee and I will drink it when I write the next article :)
Donations list:
- Dinesh Chintalapudi — 3$
- Unknown — 5$