C# For Visual Studio Code



Create a C# Project with Visual Studio Code

In this tutorial, we will learn how to create a C# project and run it in Visual Studio Code.

C# For Visual Studio Code

There are three pre-requisites before you can actually get started with this tutorial.

  1. Install Visual Studio Code.
  2. Install .Net Core.
  3. Install C# plugin for Visual Studio Code.

Once all the above requirements are met, we can proceed with the following steps to create a C# project and run it in Visual Studio Code.

Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Visual Studio Code is free and available on your favorite platform. Working with C# The C# support in Visual Studio Code is optimized for cross-platform.NET Core development (see working with.NET Core and VS Code for another relevant article). Our focus with VS Code is to be a great editor for cross-platform C# development. VS Code supports debugging of C# applications running on either.NET Core or Mono. 42 Since no one else said it, the short-cut to compile (build) a C# app in Visual Studio Code (VSCode) is SHIFT+CTRL+B. If you want to see the build errors (because they don't pop-up by default), the shortcut is SHIFT+CTRL+M. (I know this question was asking for more than just the build shortcut.

Visual

1. Open Visual Studio Code

Start Visual Studio Code and you see a Welcome page. Click on Open folder... link under Start section or click on Explorer present in the left panel and click on Open Folder button.

Best C# Extensions For Visual Studio Code

2. Visual Studio Code – Create C# Project – Open Folder

Navigate to the folder in which you would like create project and create a new folder which will be your project. In this tutorial, we will create a C# project named HelloWorld. After you create the folder, click on Select Folder button.

3. Visual Studio Code – C# – Terminal

The project is created and the same appears under EXPLORER panel. Now we need to open a new terminal to run some commands to initialize our project and get all the dependencies. Under the Terminal menu, click on New Terminal.

Terminal – dotnet new console

C# For Visual Studio Code

Run the command dotnet new console in the terminal. It will create the files ProjectName.csproj where ProjectName is the name of the folder we created for this project, Program.cs, and the dependencies in obj folder.

Program.cs contains code to print Hello World to print to the console. In the Output section, it is logged that all the required C# dependencies are installed.

4. Terminal – dotnet run

Now, we run the project by running the command dotnet run in the terminal.

The project is run and the string is output to the console.

C# Visual Studio Code Snippets

Summary

C# For Visual Studio Code

In this C# Tutorial, We have successfully created the C# project in Visual Studio Code editor.