How to Run C# in Visual Studio Code on Windows 10
When it comes to development C# is a very popular language, be it for developing web applications or games C# can be used anywhere. Also, Microsoft uses C# for app developments at a large scale so in this article let’s find out how to run C# in visual studio code on windows 10.
Video Tutorial: Run C# in Visual Studio Code On Windows
If you’re finding it hard to run C# in your Visual Studio code, then you can refer to the below video for a complete guide.
Step 1: Download & Install .Net Core SDK on Windows 10
1) Firstly we’ll download the latest version of .Net Core SDK available on the internet. Follow the below provided download link and you’ll be redirected to the official downloads page of DotNet, there click on the “Download .Net Core SDK” button and your download will start.
Download .Net Here: https://dotnet.microsoft.com/download
2) Now go to the folder where the downloaded EXE file is available, right-click on the file and run it as administrator. A small window will appear there, click on yes and the execution will begin.
3) Now .Net installation welcome wizard will appear, simply click on the install button and your installation will begin.
4) A progress bar will appear showing the installation progress, once it gets completed “The installation was successful” will appear on the screen and after that click on the close button.
Step 2: Verify .Net Version
1) To check if .Net is installed properly or not, open up your command prompt by pressing the Windows button, type “cmd” and press enter.
2) In the command prompt type, dotnet --version
and press enter to check the installed version of .Net.
Step 3: Install C# Extension & Run C# program in Visual Studio Code
1) Open visual studio code, click on the extensions button, in the search bar type “C#” and install the first option from Microsoft by clicking on the small green install button, After clicking on the install button you’ll be asked to select the desired theme options, you can select any theme you want.
2) Now again in the search bar type “Code Runner” and install the first option provided by Jun Han by clicking on the small green install button.
3) Now go to your home screen and create a new folder by any name you desire. In our case it’s myproject.
4) open this newly created folder and in the directory pathway type cmd, and hit enter just like shown in the below image.
5) A new command prompt will appear, here type dotnet new console
and press enter to create a new dotnet console.
6) Now in the same cmd window type code .
to open this project in visual studio code, for the first time vs code will take some time to load as it will be loading Omnisharp & Debugger to run C# programs.
7) Click on the program.cs file to open your pre-built C# program, paste the below-provided code snippet in the file and press Ctrl+S to save the program.
using System; namespace myproject { class program { static void Main(string[] args) { System.Console.WriteLine("Subscribe Now!"); } } }
8) When saving the file if a popup appears to install the required assets for the project simply click on the yes button.
9) Now open visual studio code settings by pressing “Cmd+,” in the search bar type “run in terminal“, scroll down a bit and check the option of the “Code Runner: Run in terminal” checkbox.
10) After that click on the open setting JSON button to edit the code preferences in visual studio code.
11) In the JSON file, type “code-runner.executorMap” within the curly braces and hit enter.
12) Scroll up a bit and in front of csharp: tag paste the below-provided code snippet
"çd $dir && dotnet run $fileName",
13) Now save the changes we’ve made by pressing “Ctrl+S” and close the Settings & json window open in visual studio code.
14) Come to the program.cs file we’ve made earlier and pressed the small play button to run the code.
15) If you see something like the below image then congrats you’ve successfully executed your first C# program in visual studio code on windows 10.
Also Read: How to run HTML code in Visual Studio Code on Windows 10