9

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.

7
  • Just curious, why dont you install visual studio community edition? It's free. Commented May 7, 2018 at 8:16
  • 1
    @VincentElbertBudiman maybe OP is not a windows user or maybe vsc is too heavy for his system. Commented May 7, 2018 at 8:18
  • 1
    You should open your folder by pressing Ctrl + K, O -> then select your folder. Commented May 7, 2018 at 8:19
  • 3
    @Alberto did you install dotnet core? Can you try dotnet new console -o myApp in your terminal? Commented May 7, 2018 at 8:19
  • Have you installed .NET Core SDK? And did you try running the command dotnet new console from a terminal, instead of running from the terminal in vs code? Commented May 7, 2018 at 8:20

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

You can see if you’ve got SDK properly installed using dotnet version and seeing if the version provided is the one you installed.

Just to be sure you can restart computer to make sure a new PATH variables will be used - that was an issue in one of my previous work laptops :)

Good tutorial on first .NET (Core is obsolete since version 5) is here: https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install. Every step is in detail there - it’s a good starting point for you :)

For creating a new project: dotnet new <project type>

Documentation: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-new

Btw: .NET Core SDK 2.1 will reach End of Support on August, 21. I suggest installing a newer one.

Comments

0

Make sure you have DOTNET installed on your computer. Open the terminal and then run dotnet new console

This is going to create some projects and a simple hello world C# application. It will take some time..

You can code some c# in the Program.cs file and then open the terminal and type dotnet run and press enter.

If it doesn't work and it shows command not found, make sure you have installed .NET sdk .

Hopefully it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.