Have you ever been curious about learning to write some C# code, but you weren’t sure where to start? Then you have come to the write place! This post is going to teach you the first step to all C# development. That is setting up your development machine.
The purpose of this tutorial is to show you the basics of what it takes to set up your computer to be a lean, mean, C# development machine. So, by following this tutorial your computer will be ready to follow along and write just about any C# code you find on this, or any other, site.
This tutorial is meant to be completely hardware agnostic. That means that regardless of the type of computer you are using, for the most part, you should be able to follow along fairly easily.
The only thing that changes for this tutorial depending on what type of computer you are using is what the software installers look like. Installation packages for different operating systems typically look a little different. All you typically need to worry about is leaving the default options and click the “Next”, “Continue”, “Finish”, and “Close” buttons. If you can do that, you have nothing to worry about. C# development will be well within your reach.
By the end of this tutorial, you will be able to use your computer to write several different types of C# applications AND you will know how to create a basic application using C# and .NET Core.
Let’s get started!
Getting Setup for C# Development
First, we are going to start by getting your computer ready for C# development. For this tutorial you will be able to follow along with any computer running either Windows, Mac OSX, or Linux because we are going to be taking advantage of .NET Core.
If you are unfamiliar with what .NET Core is, you can check out the end of my Understanding C# vs .NET post.
Install .NET Core
It’s actually quite simple to install .NET Core. You simply head over to the .NET download page.
Depending on what operating system and browser you use, the page will try to determine what you are using and show you the proper download. I am using the Chrome browser on a Mac and this is the screen that I see:
As you can see, the page has selected the macOS tab and is showing me the proper download button. If it doesn’t show you the proper tab, simply select the one you need.
Click the “Download .NET Core SDK” button displayed on your tab.
This will download the .NET Core SDK (Software Development Kit) as well as the runtime. This will be everything you need to begin C# development on your computer.
Double click on the downloaded file and following the installation instructions. They are typically rather simple and only require you to click a couple of “Next” buttons and a “Finish” or “Close” button when done.
Once the installer has done its job, the next step is to make sure that it has been properly installed and ready to go.
To do this, all you need to do is open a command prompt (on Windows) or a terminal application (on Mac or Linux) and issue the following command:
If everything is working correctly, you should get a response back displaying the version installed. It should look something like the following:
If you got an error or something saying that “dotnet is not a command”, that is not uncommon. If that was the case, make sure to close ALL of your command prompt or terminal windows and try again.
This will usually fix the issue.
Now it’s time to move on to tooling.
Installing Visual Studio Code
Now that you have the .NET Core SDK installed, you need tools that will enable your C# development and help write C# code and turn it into an application you can run on your computer.
Do you HAVE to have a “fancy” code editor to write C# applications?
You could definitely do it with a built in text editor like Notepad or TextEdit. But using a “code editor” will provide you with some really cool features that will make the process a little easier and help you learn the C# language a little faster.
To download Visual Studio Code you simply need to head over to the download page. Once again, the page will do it’s best to determine what operating system you are using, and provide you with the appropriate version.
It will look something like this:
All you need to do is click on one of the GREEN download buttons to download Visual Studio Code to your computer.
After you have download the installer, simply double-click the file and follow the on-screen instructions.
Once again, it will be a very simple install, typically involving a few “Next” or “Continue” buttons clicks followed by a “Finish” or “Close”.
Once this process is finished, you can open Visual Studio Code and take a look at all of its glory. To open it, simply go back to the command prompt or terminal application you used before to verify the installation of .NET Core. Once there, type the following command:
After typing the above command and hitting Enter on the keyboard, you should see something like this:
If you are this far along…CONGRATULATIONS!!!!
You are now ready to start writing C# code!!!
But before we get that far, let’s take a little tour of Visual Studio Code just to get our bearings.
Visual Studio Code Primer
Visual Studio Code is an incredibly powerful code editor that contains so many features, I could spend a ridiculous amount of time, blog posts, and online courses only going through it’s functionality. I know that’s not why you are here right now, so we will just focus on the absolute basics so you can get to the code.
In order to get through this tutorial, you really only need to know about 2 parts of the Visual Studio Code interface.
- The Activity Bar
- The Editor
Let’s take a quick look at both of these.
The Activity Bar
The activity bar is the vertical strip on the far left of the interface. It looks like this:
By default, the activity bar has 5 icons the provide very distinct pieces of functionality. Here is a quick description of each of the buttons on the activity bar and what they do.
The first icon will display the explorer. The explorer will show all the files and folders in your current working directory. This will allow you to navigate your entire project structure. When you select a file from the explorer, Visual Studio Code will display the file contents in the main part of the interface.
The search icon is fairly self-explanatory. When you click on the search icon, Visual Studio Code will display the search box on the left portion of the interface. The search box allows you to search for files, folders, and the contents of files for any particular word or phrase. This is a very useful feature.
In my humble opinion, if you are just getting started with C# development, or learning to write code in general, you don’t need to worry about learning about source control. You should spend your time having fun and learning to write some basic code and maybe a few simple applications. Simply stated, source control allows you to not only save your code, but also keep track of your changes and share your code with others.
If you are interested in learning a little more about source control, start with learning a little about GitHub.
Debugging is very important to learn. I will spend several other posts and tutorials talking about debugging. In short, debugging is the process of “slowly” running through your application’s code and watching it execute any lines you want to make sure it’s working as you desire.
The last button in the activity bar, but definitely not the least, is the extensions button. When you first download Visual Studio Code, it’s quite basic, although powerful. You are able to add additional functionality and programming language support by installing extensions.
We will see an example of using extensions shortly.
The editor is, by far, where you are going to spend most of your time in Visual Studio Code. If you were to close the Welcome tab when you open Visual Studio Code you will see a large, blank space. This is the main editor space.
It may not look like much now, but it will soon be full of all your beautiful code!
Installing an Extension
Visual Studio Code comes with a lot of great functionality out of the box. But in order to take full advantage of this great code editor for your C# code, you will need to give it a little help.
Let’s start by clicking on the last button in the activity bar for extensions.
When the search box appears at the top, simply type “C#” in the search box and click Enter. You are looking for the first option that says “C# for Visual Studio Code”. It it created by Microsoft.
Click on that entry.
You should see something like this:
That is the one you are looking for. Click on the green install button.
After you click the install button, the options will change to “Reload” and “Uninstall”.
Click the blue “Reload” button, and you will now have the full power of the C# extensions installed into your instance of Visual Studio Code.
When it comes to C# development, the sky is now the limit!
Well done! You did it!
Now that you have your computer setup for C# development, you are ready to actually write some code.
I know that was a lot to go through. And if you have never done anything like this it can be a little scary and overwhelming. But the important thing to pull from this is…
You can do it!
All it takes is a little determination and some guidance…and luck. Yes, luck does quite often play a part in all of this.
Don’t stop now! Continue your momentum and checkout the next tutorial on
where you will learn the basics of creating your first C# application and learn some of the fundamental building blocks of the language.