Run and compile C# in Visual Studio Code with .NET Core

Tuesday, September 27, 2016

How to run and compile C# inside of Visual Studio Code with .NET Core. In this short and simple tutorial I will write about this topic. For this tutorial you will need couple of minutes, VS Code, .NET Core and that's it.

So let's begin with tutorial.

First of all you will need to have installed Visual Studio Code on your machine. These steps are really simple so I guess that you know how to install it, but here are some fast steps on how to install it.

For those who are not familiar with .NET Core I will have one separate blog post about it, you can find out more about it here.

This tutorial will be successful if you will be able to run and compile C# inside of Visual Studio Code.

Download and install Visual Studio Code:

Download and install it on your machine. Go to this URL



Click on big green button Download, and wait for it to download it for you. After you click on button wait couple of seconds and this very lightweight code editor will start to downloading. Size of file is about 30 MB so depending on your download speed it should be done after couple of minutes or seconds.

Install Visual Studio Code:

When download file is done, click on it and follow the steps bellow:

At first screen go Next, at second you need to accept terms and conditions so select I accept the agreement ... and click on Next, if default installation path is ok with you click on Next, after that also Next.

At this screen by default this selected options are good for you. you can also select first one to create desktop icon for you.

After Next all you need to do is to click on Install and after couple of seconds you will have installed your new lightweight code editor Visual Studio Code.

After installation is done you will get this screen and you can launch Visual Studio from installer or you can launch it later.


Install C# extension:

After you have your VS Code installed, run it and now we need to install C# extension for VS Code.

Inside of VS Code run this keyboard short cut: CTRL + SHIFT + X ... and you will get this kind of screen:


For this tutorial we need C# Extension go to Install:


After couple of second we will need to enable it and VS Code will restart by itself:


Download and Install .NET Core:

Now we need to download and install .NET Core. Go to this URL Here and download ".NET Core SDK for Windows".

Run the exe installer. After couple of seconds you will get this window:


Run and compile C# 

Now we are ready to start coding C# inside of VS Code. After this we can create new folder on desktop or any other location, mine will be on desktop called CSharpExample. Navigate to this folder via VS Code, you can do it by cmd or open VS Code and select your folder:


Now when we have our folder opened by VS Code, we need to open terminal you can use command prompt or terminal inside of VS Code. I will use terminal and to open it go to View -> Integrated Terminal.

Inside of terminal type command: dotnet new
and you will see that now we have created Program.cs and project.json files after that we need to run command: dotnet restore
to restore some dependencies like this;


If we want to compile and run this code we can do it with command: dotnet run




We have intellisense and using VS Code we can debug our applications too:




As you can see we have successfully run and compiled C# inside of Visual Studio Code with .NET Core. When I saw this for the first time I was amazed by this so I decided to make blog post about it.

I will write about debugging in VS Code in some other blog post.

Hope that this short and simple tutorial was helpful for you, if it is you can share it with your friends.

Best regards! Almir Vuk 

You Might Also Like

6 comments

  1. Thanks Almir, the "Run and compile C#" section help me to understand how to run C# from VSCode.

    ReplyDelete
  2. The post is more than amazing, yet I am facing some difficulties running C# guys. could you please make another post or blog and walk me through the steps needed to be done in order to run C# on VScode.
    of course if you dont mind...
    I have been trying to make it work, but it is not responsive yet.

    Thanks for everything so far and looking forward to hear from you again

    Best regards
    ABMA

    ReplyDelete
    Replies
    1. Hi,

      Thank you for comment, can you please explain what issues you have with .net core and c#. I will be more than happy to help you :)

      Best regards!

      Delete
  3. Vuk I'm very thanksgiving! I read several pages include Microsoft and I didn't understanding how to compile ans to run my code write in C#, your page help me do it.

    ReplyDelete
    Replies
    1. Hi Sergio,

      Glad to hear that!

      Wish you a lots of luck with coding!

      Delete