How to create a console application in visual studio code?

In this vs code tutorial, we will discuss how to create a console application in visual studio code. Also, we will see how to create and debug the C#.Net console application using visual studio code.

Visual Studio Code

Visual Studio Code is a free code editor developed by Microsoft for Windows, Linux, and macOS. We create the C# Console application in Vs code with the help of .NET Core.

Visual Studio Code (Vs Code) is optimized for cross-platform .NET Core development. Visual Studio Code is a lightweight but powerful source code editor that runs on your desktop and is available for Windows, macOS, and Linux.

Use Visual Studio Code with the C# extension to get a powerful editing experience with full support for C# IntelliSense and debugging.

First, install the below components.

  1. Install Visual Studio Code.
  2. Install the .NET Core SDK.

Create a console application in visual studio code

Now, let us see how to create a console application in visual studio code. Here we will create a simple “Console demo application” program on .NET Core.

Follow the below steps to create the console application using visual studio code:

Open Visual Studio Code, then open a project. Then open the Integrated Terminal from Visual Studio Code selecting.

Terminal > New Terminal from the sub-menu.

The dotnet command creates a new application of type console for you. The -o parameter creates a directory named ConsoleApplicationDemo where your app is stored and populates it with the required files. The cd ConsoleApllicationDemo command puts you into the newly created app directory.

Create console application in visual studio code
Create a console application in visual studio code

Then Switch the path to the folder ConsoleApplicationdemo using the below command.

D:> cd ConsoleApplicationdemo

Enter the below command to open the ConsoleApplication project in VS Code

D:\ConsoleApplicationdemo> code.

create console application in vs code
How to Create a console application in visual studio code

Then again open the terminal command prompt in visual studio code.

Run dotnet restore command to resolve the dependencies of the project and give you access to the required .NET Core packages that are needed to build your project.

visual studio code compile c#

Type the following command: dotnet run. Run the console application and the below screen output appears.

visual studio code debug c#
Visual studio code create a console application

This is how we can create a console application using visual studio code.

Now, we will see how to debug a C# console application using visual studio code.

Debug console application in visual studio code

One of the key features of VS Code is its great debugging support. VS Code’s built-in debugger helps accelerate your edit, compile, and debug loop. Now, we will see how to debug a console application C# in visual studio code.

Follow the below steps for the C# debugging in visual studio code.

The first time you open a C# Program.cs file in Visual Studio Code the below pop window appears. Visual Studio Code should prompt you to add the missing assets to build and debug your app. Select Yes.

visual studio code c# 8
Debug console application in visual studio code

Start the install OmniSharp loads in the editor.

how to run a c# program in visual studio code
Debug console application in visual studio code

After completing the below message shows in the command window

Debug console application in visual studio code
Debug console application in visual studio code

VS Code left Navigation — click on Debugger Icon

Locate the green arrow at the top of the pane. Make sure the drop-down next to it has .NET Core Launch (console) selected.

how to debug console application in visual studio code

Add a breakpoint to your project by clicking on the editor margin. To start debugging, press F5 or select the green arrow, Show the local variable value in the top left pane.

how to debug c# console application using visual studio code

Visual Studio Code Top Extensions

In the Visual Studio code, there are more debugging extensions for debugging other languages and runtimes (including PHP, C#, Python, C++, PowerShell, and many others), look for Debuggers extensions in our VS Code Marketplace or select Install Additional Debuggers in the top-level Debug menu.

how to run a c# program in vs code
Visual Studio Code Top Extensions

You may like the following visual studio tutorials:

In this tutorial, we learned how to create a console application using visual studio code, also we saw how to debug a c# console application using visual studio code.