How to Use The Command Line In C# to Create A New Application
The terminal is a great place to streamline all commands that you need to execute when building and running your code.
As a beginner, it can seem a bit confusing, and even intimidating when navigating the terminal. The abbreviations are wacky. The terminology is new. And are you even inputting the right amount of spaces?
It can all feel super overwhelming as a beginner. However, this article aims to provide simple tips on how to use the terminal for an easier, more efficient coding experience!
If you are using Visual Studio, to locate the terminal, click on “View”, which can be found at the top of your screen.
If you are using Visual Studio Code, the terminal can be found at the top of the screen. It’s a bit more readily apparent.
Once you open the terminal, a black box should appear. This is where you will be doing your typing. It’s probably also best to mention at this point that the terminal is very sensitive when it comes to inputting the right amount of spaces. A good rule of thumb is to never input spaces after the last command word. Unless you are specified to do so, adding extra spaces after the last command word will disable the command.
If you want to start a new project, you can actually start it all from the command line! First, you decide where in your computer you want to store your project. Let’s say you choose to store your project in the “Projects” folder. In the terminal, you type:
cd Projects
Then you hit “enter”. This will take you to the Projects folder in the terminal. Any commands you make under the Projects folder will affect the folder.
The abbreviation “cd” stands for “change directory”, you will need to use this abbreviation when jumping in and out of a folder. To get out of a current folder, you simply type “cd” and then hit enter.
So, back to creating your new project within the Projects folder. To start a new console application, you will need to use the dotnet command line tool. In the terminal, you will need to type:
dotnet new console -o HelloWorldApp
The “dotnet new” command creates a new C# application, while the “console” specifies the type of application we will be building. The “-o” denotes the name of the output file, which in this case, is “HelloWorldApp”.
Once you hit enter, the application is ready for coding. Go to your Projects folder and you will find your HelloWorldApp folders ready for tinkering!