Run and compile C# in Visual Studio Code with .NET Core
Tuesday, September 27, 2016
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.
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.
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
6 comments
Thanks Almir, the "Run and compile C#" section help me to understand how to run C# from VSCode.
ReplyDeleteNice to hear that!
DeleteThe 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.
ReplyDeleteof 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
Hi,
DeleteThank 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!
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.
ReplyDeleteHi Sergio,
DeleteGlad to hear that!
Wish you a lots of luck with coding!