Table of Contents

Overview

Required software

Setting up the environment

  1. Download and install Visual Studio Code

  2. Download and install .Net Core SDK

  3. Intall the extension Omnisharp in Visual Studio Code

Hello world

  1. Open a project:

    • Open Visual Studio Code.

    • Click on the Explorer icon on the left menu and then click Open Folder.

    • Select the folder you want your C# project to be in and click Select Folder. For our example, we’ll create a folder for our project named 'HelloWorld'.

  2. Initialize a C# project:

    • Open the Integrated Terminal from Visual Studio Code by typing CTRL+` (backtick). Alternatively, you can select View > Integrated Terminal from the main menu.

    • In the terminal window, type dotnet new console.

    • This creates a Program.cs file in your folder with a simple "Hello World" program already written, along with a C# project file named HelloWorld.csproj.

  3. Resolve the build assets:

    • For .NET Core 2.0, this step is optional. The dotnet restore command executes automatically when a new project is created.

  4. Run the "Hello World" program:

    • Type dotnet run.

Debug

  1. Open Program.cs by clicking on it. The first time you open a C# file in Visual Studio Code, OmniSharp will load in the editor.

  2. Visual Studio Code will prompt you to add the missing assets to build and debug your app. Select Yes.

  3. To open the Debug view, click on the Debugging icon on the left side menu.

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

  5. Add a breakpoint to your project by clicking on the editor margin (the space on the left of the line numbers in the editor).

  6. Select F5 or the green arrow to start debugging. The debugger stops execution of your program when it reaches the breakpoint you set in the previous step.

    • While debugging you can view your local variables in the top left pane or use the debug console.

  7. Select the green arrow at the top to continue debugging, or select the red square at the top to stop.

For more information and troubleshooting tips on .NET Core debugging with OmniSharp in Visual Studio Code, see Instructions for setting up the .NET Core debugger.