This article will introduce you to the absolute basics of using the popular Microsoft IDE, Visual Studio. By the end of the article, you should be set up and ready to start writing your own software for your projects.
Installing Visual Studio
The setup procedure is straightforward, but there are a few things worth mentioning. After initializing the installer, select the version you want to install:
Enterprise is for large(r) teams and companies, Professional is the version for small(er) teams and Community is a free variant for individuals. After choosing a version, select the components you want to install:
This depends on what you want to develop. If you are new to Visual Studio, I recommend you stick to the options in the Workloads tab. However, if you know what you’re doing, or you’re feeling particularly ambitious, you can select and deselect options in the Individual Components tab. After you’re done, start the download by clicking Install:
This shouldn’t take too long, Once the installation is complete, you’ll receive this message:
Launching Visual Studio for the First Time
After you complete setup and installation, go ahead and launch the application. You’ll get asked whether you want to login to other services like GitHub or Azure. This is completely optional and you can completely skip this step. Upon logging in and choosing a design, you should see a window similar to this:
To get started, choose File, then New, and Project. A dialogue should pop up that’ll allow you to create a new project:
Choose the programming language you want to use on the left-hand side of the window.
The middle section of the window shows the available templates for your selected project type. You can enter a name, a path, and some programming languages, which will allow you to choose a compiler/interpreter version.
Click Ok to create your new project.
How to Write Code in Visual Studio
When you first start Visual Studio, the UI can look intimidating. However, writing programs works similarly to a simple text-editor. However, there are a few features that’ll increase your productivity and code quality.
The first thing you may notice is this suggestion that pops up that when you start typing a command:
You can use the auto-completion to quickly insert the highlighted command by hitting the enter key. Some constructs, like the for-loop, allow you to add a complete template by pressing the tab key twice. The green and yellow bars next to the line-numbers indicate saved and modified code.
A similar helper tool shows the documentation of a function while you type its name:
You can use the up and down keys on your keyboard to display different method variants.
Debugging in Visual Studio
You can set a breakpoint by clicking the gray area left of the line numbers. To remove a breakpoint, click the red circle that appears:
Now, when you execute the program, it will stop at the breakpoint. This allows you to debug it. To check a variable’s value, hover the mouse cursor over the variable and a small pop-up should appear:
Click the pin-needle to prevent the pop-up from disappearing. This allows you to inspect how a field’s value changes over time, e.g., in a loop. Some variables like objects and arrays, allow you to check each value they hold. You can also change the variable’s value by double-clicking the pop-up.
To continue your program, use the tools in the main menu bar:
Alternatively, you can also press F5 to continue the execution, Shift + F5 to stop debugging, F11 to step into a statement, F10 to step over it and Shift + F11 to step out of it. You can also add and remove existing breakpoints while debugging.
Visual Studio is Free and Worth Giving a Try
Visual Studio is a really powerful IDE and, because there’s a free version available, it’s totally worth testing out. It may look a bit intimidating when you first see it, but it’s easy to dive in a get familiar with its features.
Arduino Programming in Visual Studio
Plugins are available for Visual Studio, including some that allow you to utilize Visual Studio to program and debug your Arduino projects. Check out my tutorials about programming Arduino in Visual Studio here: