Creating a New .NET Project

C# From Scratch Part 2.1

Ken Bourke
Dec 11, 2020 · 4 min read
Use dotnet new console to create a new .NET project in the src directory

Welcome to another part of the series C# From Scratch, a course dedicated to teaching you everything you need to know to be productive with the C# programming language.

In the previous part of the series, we learned how to interact with .NET on our machines using the .NET CLI, a tool that was installed as part of the installation of the .NET SDK. That part of the series is available here.

In this part of the series, we’ll create our first C# project using the .NET CLI.

Creating the Project

Use the command ‘dotnet new’ to create a new .NET project.

The command returns with some information about the different options that can be used to create a new .NET project.

The dotnet new command returns information about options

The most important options here are the template options that are available. To create a new .NET project, you have to tell .NET what project template you want to base your project on.

This template is used by .NET to create the basic structure of your project. You can see that there are many different templates available to create many different types of applications.

An application that we run from the Command Prompt window is called a Console Application in .NET. You can see from the information returned by dotnet new, that to create a Console Application, we have to use the option ‘console’.

Use console option to create a new Console Application

We’ll be working on building a Console Application throughout the rest of this series, so we’ll use the ‘dotnet new console’ command to create a Console Application.

Before we create the application though, let’s create a directory for the project to live in. In the Command Prompt window, use the ‘mkdir’ command to create a new directory called Gradebook.

Use the mkdir command to create a directory for the project to live in

Now navigate into the new directory using the ‘cd’ (change directory) command.

You can see that you have successfully navigated into the Gradebook directory because the Command Prompt prompt has updated to reflect our new location in the file system.

Change into the new directory with the cd command

Finally, you can list the contents of the directory by using the ‘dir’ command. You should see that the new directory is completely empty.

Use the dir command to confirm that the new directory is completely empty

We could create our .NET project here, but instead we’ll try to develop the conventional structure of .NET projects that you will see on larger applications.

Use the mkdir command to create two more directories in the Gradebook directory. The first directory is called ‘src’ (short for source), this is the directory where our source code will live. The second directory is called ‘test’, this is where our unit tests will live.

Use the ‘cd’ command to navigate into the src directory and run the command ‘dotnet new console’ to create our .NET project in the src directory.

Use dotnet new console to create a new .NET project in the src directory

Once again, you can use the dir command to list the contents of the src directory. You can see that several files and folders have been created.

This is your .NET project.

Use dir to list the contents of the src directory

What’s Next?

In this part of the series, we learned how to create a new .NET project using the dotnet new command and a template option.

In the next part of the series, we’ll explore the structure of the .NET project and learn how to run our project from the Command Prompt window. You can find that part of the series here.

Missed a part of the series? You can find an overview of the series and links to all previous parts on the index page.

The Startup

Get smarter at building your thing. Join The Startup’s +724K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store