Create first c sharp program with visual studio code editor

Visual Studio 2017 Community is a great ide when it comes to creating windows application but because of it’s large file size (minimum around 40+ GB) it will take longer time to download all those files we need for the application development include the .net framework plus the IDE itself. For those of you who has a slow Internet connection, a 40 GB of files will take you about a day to download which is the reason why we really need to look for an alternative of Visual Studio 2017 Community if we can.

If you are also like me who has a slow Internet connection then you might want to consider visual studio code which looks good to match eclipse in the future. Although it is still very fresh when compares to visual studio but this code editor, in my opinion will at least be able to match notepad++ and Brackets at the moment. After using visual studio code for a while I just want to give all my praises to this great code editor and I really do hope Microsoft will look into the download size’s issue of the visual studio community which I have mentioned earlier in my post and (perhaps) allows the windows app developer to use the visual studio code editor as an alternative for visual studio 2017 community when it comes to windows app development. Besides that, I hope Microsoft might also wants to consider to add in the mobile application development capability to this editor so we can start to develop mobile application for both iOS and Android OS in visual studio code just like what we can do with the visual studio 2017 community. One more cool thing, with additional extensions develop by the visual studio code’s developers we can now write application in other programming language as well such as python and c++ in visual studio code.

Alright, so much for the introduction part now let create a simple c# console program in visual studio code editor. First of all download the visual studio code editor if you do not have one yet.

Once you have installed the editor go ahead and download the c# extension which you will need for developing c# application. If you have installed the visual studio code editor in your laptop or computer then once you have clicked on the download button on the c# extension download page the code editor will open automatically and you can then download this extension within the visual studio code editor. Close the Visual Studio Code editor for now after you have installed the extension.

Next, download the .NET SDK.

Then start the code editor again and goto File->Save Workspace As and select a location in the hard drive for the workspace file, I prefer to create a folder and then put everything in there include the workspace file and the projects folder, call the workspace ‘CSHARP.code-workspace’, you can give any name which you wish to with the .code-workspace extension. If this is the first time you use this editor click on the Add Folder button under the project explorer window to create a new project folder in the same location as the workspace file.

create the hello folder for the project
create the hello folder for the project

You can call the folder any name you wish to, for example Hello. Now the folder/file tree under the explorer window should looks like this.

The folder tree
The folder tree within the explorer window

Next select the Help folder by left mouse click on it. Then goto View->Integrated Terminal. Type in dotnet new console to the terminal then press enter. If this is the first time you are using this editor then the editor will need to download some extra files before it can create your first c# program for you. After the code editor has finished creating the new c# program, you will find a new Program.cs file under the Hello folder which will print the hello world message after you have typed dotnet run into the console and then press enter.

Print Hello World in the terminal
Print Hello World in the terminal

There goes our first c# program runs in visual studio code editor, if you have made any changes to the c# program do make sure that you save the file before you run it again or you can select Auto Save under the File tab so you do not need to save your program every time you make a change to it.

That is it for our first c# program in visual studio code editor, you can also change the name of the Program.cs file if you want to by right click on it and select Rename from the pop up window. Here is the c sharp program generates for you by the code editor.

using System;

namespace CSHARPP
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

It is the same as any c# code we write to generate a simple Hello World greeting!

Now the file tree should looks something like this in the explorer window.

The file tree for the entire project
The explorer file tree for the entire project

It is indeed a little bit hard to create a c sharp project in visual studio code editor as compared to visual studio 2017 community, isn’t it? Oh well!

Leave a Reply

3 Comments on "Create first c sharp program with visual studio code editor"

avatar
  Subscribe  
newest oldest most voted
Notify of
trackback

[…] by /u/IslandTropical [link] […]

McNerd
Guest
Here via reddit, with two notes: * Workspaces are optional, you can skip all of that. Just use folders unless there’s a compelling reason not to. * Exaggerating the download/install size of VS helps nobody. You download a 1MB installer to initiate the install, not an ISO or whatever. The base installation is something like 5GB (probably less) and you pick-and-choose what specific features suit you. That means NOT downloading things all at once and NOT downloading things that are irrelevant to you. My current install is 27GB which includes quite a few workloads, and 19GB of that is Xamarin… Read more »