In this article, we explore the Visual Studio Code is a free code editor developed by Microsoft for Windows, Linux, and macOS. It is a lightweight yet powerful source code editor which runs on 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.
Creating a Console Application in VSCode
Let's get started and create a simple console application with Visual Studio Code and .NET Core.
So first we need to create a folder on the hard drive which will store our solution files. I'm going to use
C:\Dev\ConsoleDemo\ but you can use anything you want.
Open up Visual Studio Code and click on extensions tab. Search for and install the Microsoft C# for Visual Studio Code extension. At the time of writing v1.23.9 is the latest version.
Next, open the Integrated PowerShell Terminal from Visual Studio Code by selecting
New Terminal or pressing
On the command line change the directory to C:\Dev and enter the following command:
dotnet new console -o "ConsoleDemo"
This will create the directory ConsoleDemo and install the VS project files. You can then select
Open Folder and navigate to the directory just created.
The first time you open a C# Program.cs file in Visual Studio Code it should prompt you to add the missing assets to build and debug your app. Select Yes.
Next, in the terminal, 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.
You can now run
dotnet run to run the console application and the below screen output appears.
Debugging Console Application in VSCode
One of the cool features of VS Code is its great debugging support. VS Code's built-in debugger helps accelerate your development lifecycle.
To access the debug tools click on the debug button on the left hand menu in Visual Studio Code. Add a breakpoint to your project by clicking on the editor margin in Program.cs, in the same way as you would in Visual Studio 2019. To start debugging, press F5 or select the green arrow at the top of the debug window.
Debugging works just like debugging in Visual Studio Professional, F10 steps over, F11 Steps into. F5 to continue running. For more information on using the debugger, including watches, locals and call stacks, see the article Error and Exception Handling in Visual Studio and check the heading "Using the Visual Studio Debugger".