Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a C# project using Visual Studio Code?

I want to try Visual Studio Code to compile the typical "Hello World" in C#. I did the following:

  • I installed Visual Studio Code.
  • I added the extension C# for Visual Studio Code (OmniSharp).
  • I installed the 64-bit SDK 2.1.10.
  • I created a folder to contain the project I want to create.
  • I opened the folder with Visual Studio Code. On the terminal I wrote:
dotnet new console

but, unlike the tutorials I see on the web, nothing happens. The project is not created but I do not see any error messages either.

I appreciate the help to know how to create, edit and compile a project in C# from Visual Studio Code.

like image 535
Alberto Avatar asked May 31 '26 14:05

Alberto


1 Answers

This might be a late one, but I hope it helps. I assume that you have .Net already installed, you can check by opening the cmd and run the command dotnet --version
I also assume that you have installed Visual Studio. Here are a few steps I took to run the C# code using visual studio.

  1. Install code runner:
    Go to the extensions on your visual studio, click on Extensions icon. On the search field, type Code Runner, choose the first option and click on the install
  2. Navigate to settings from File > Preferences > Settings from Visual Studio
  3. Search for run in terminal and scroll down the page. Enable the Run in terminal for the code runner as shown in the image Below.

Run in Terminal - Code Runner

  1. Now click on Open Settings JSON button shown in the Top right (second after the run icon) as shown below

Open Settings JSON

The resulting window is as below. Add a comma (,) at the end of the existing setting, then type code runner, choose the option with code-runner.executorMap

Code Runner Executor Map

  1. Scroll down the List, where there is the key csharp. Replace the value scriptcs with cd $dir && dotnet run $fileName

Select executorMap

  1. Save all the changed - File>Save or Ctrl+S

Yey!!! You can now run your code by clicking the run button or using code runner

like image 107
Michael Elimu Avatar answered Jun 02 '26 04:06

Michael Elimu