Getting Started with Visual Studio Community 2019

A few quick notes before I dive into the meat of the article.

  1. I will not automatically show you the best technique for advanced programming; not because I want to make you inferior, but because I want to slowly introduce you to more and more advanced concepts over time. So there may be some things I show you now that I’ll later tell you not to do normally. Don’t panic or get upset; those lessons are meant to help you understand important concepts, and it’s just as important to learn what NOT to do as it is to learn what you CAN do.
  2. Most of the stuff I’ll show you will be using Visual Studio 2019 Professional. For the most part, you’ll see the same tools as I would, but if something is missing or seems odd, don’t worry! I won’t use anything that isn’t available for the Community Edition – and if somehow I manage to do that, just send me a message and let me know; I’ll get you the info you need to proceed.
  3. Don’t panic about the complexity of what you’ll see. Remember that a key to something complex is to focus on the small pieces. If you don’t panic and worry about the big picture, you’ll have the Sistine Chapel before you realize it.

Launching Visual Studio

Assuming you’re using Windows 7 or 10, go to your Start menu and look for “Visual Studio 2019”. You’ll get asked if you’d like to sign up for a Microsoft account.

You can skip past (click Not now, maybe later). Then you’ll get presented with this screen:

This will let you select the configuration options for using the software in an optimal way. for the “Development Settings:” drop-down menu, choose Visual C#. You can choose the color scheme you think you’ll like. You can always change it later if you like. At some point I will do an article on playing with the preferences for the IDE; and there are a LOT of options. For now, I’m going with Dark. It’s easier on my eyes, so that’s what I tend to stick with. The theme won’t affect what tools are available, so just pick whatever seems best to you for now.

Welcome to… another menu screen…

OK, this is actually a good thing. From here, you’ll be able to start building your first application. You won’t initially see anything on the left side of the screen under “Open recent”; that’s because you haven’t done anything yet. In the future, programs you’ve written will be available here for you to reopen.

For now, we’re going to Create a new project (the button on the lower right of the screen). Good grief! What is all this?

Again, relax. This is where we select the type of project we’re going to work with. This give you an idea though of what sort of capabilities you’ll have for development. You may not see as much as I have here, but you’ll still likely see a lot of options in that right-hand list. Let’s filter down to something more manageable. Under “All languages”, select C#. Under “All platforms” select Windows, and under “All project types”, select Console. At this point, you should see a MUCH smaller set of options. The ones you’ll most likely see are “Console App (.NET Core)”, “Console App (.NET Framework)” and “Workflow Console Application”. As long as you see the first two options, we’re in good shape. Select “Console App (.NET Framework)” and click “Next”.

This is the option to set up a project that will work specifically on Windows, and run in what you may recognize as a command-line interface (some people will call it a DOS interface, and while that’s fine, understand that DOS really refers to an operating system that is really no longer in use). Regardless of whether you call it command line or DOS, this will let us build a simple text based application.

Egads, another screen?! Yes!

Yes. But don’t worry, we’re almost through this initial set of steps. On this screen, we’ll have a few options for what we can do. First, let’s give our project a name. It default to ConsleApp1, but that’s not an entirely useful name. You’d like to have SOME idea of what the app is for. It’s not going to be much, in this case, but we should have something better than ConsoleApp1. Change this to say HelloWorld. Note, there shouldn’t be any spaces in this field if you can avoid it. You will probably notice that as you renamed the project, the Solution name field also changed to HelloWorld. Let’s explain this just a bit.

Projects? Solutions? Huh?

OK, this isn’t really all that bad, but it’s valuable to know. Most of the time when you want to build a larger sort of application, you won’t want to slap everything into a single big file. It makes it hard to sort through problems, it makes the program potentially WAY larger, and if you want to make some of your code re-usable, this isn’t going to make that task easier.

A Solution is a container for a series of related projects. Some projects will be actual applications. Some will be collections of functions you may choose to reuse later. Some projects might be for building a website. So you could, for example, say you have a project for an application, a project for a website, and a project that has some code used by both. Each part is it’s own project, but they are all part of the solution. Later, you might have an entirely new solution, but you’ll want to reuse the library project; can you can do that, by copying it from one place to another.

If you want an analogy: imagine you’re hungry. You want to make dinner, and a dessert. You have ingredients in your fridge. Well, some ingredients (like milk or eggs) are used in many different recipes. You probably don’t keep separate batches of eggs and milk in different fridges. You keep them together, and when you need an egg, you get it. When you need milk, you get it. What about salt or sugar? Well, you don’t need to keep them in the fridge, but you’ll have them in another cupboard. Again, not all recipes need sugar or salt, but if you do, you can get them out of the right place. You’ll have a recipe, which is the instructions of how to use those ingredients to make your recipes. And you don’t just mix all the ingredients for both recipes together (if you think strawberry jelly goes well with fish, maybe you would, but frankly, your nuts).

So you follow your recipes, produce each of the parts of your meal. And when you’re done, you can now enjoy the fruits of your labor. Congratulations; you solved the problem of being hungry.

The places we store ingredients, and cookware and whatnot; those are all library projects. The recipes might also be a form of library. The actual process of preparing the recipes are also projects, but instead of being libraries, they’re programs. They are the direct control over the process of making your meal. And the entirety of making the meal and dessert? Well, your problem was that you were hungry. The solution was to make the recipes.

So a solution is a container for projects. In the case of HelloWorld, we don’t need to separate them any more than this, because we’ll only have one simple project in here. They can have the same name and it won’t be an issue.

For the Location, you can leave it to default to wherever it is. More than likely you’d see something like “C:\Users\someuser\sources\repos”. For the time being, that’s just fine. Later on we can look at other ways and places to store things.

You may have noticed a checkbox that says Place solution and project in the same directory. Frankly, I don’t recommend that. If you leave it unchecked, you’ll have a folder for the solution, and then each project will have it’s own sub-folder. I find that easier to deal with, personally. Finally, you’ll see a drop-down box that is labelled for Framework. If you click on that, you’ll see a ton of entries like .NET Framework 2.0, .NET Framework 3.0, etc. It’s not likely you’ll ever need to go to a much older version than what’s current, but it is useful to have all of the options in there in case you later download a project from the web and want to try to update it to what’s current. As of this article, the current version is .NET Framework 4.7.2. If you did your install of Visual Studio right in the last article, you can just select this value if it’s not already set, and click “Create”.

You’ll now have a much more complex looking screen, with a big window in the center with a lot of text in it.

Before you can say “What is all this?” let me explain what all of this is.

The Visual Studio Interface

Remember, first, that Visual Studio is an IDE (integrated development environment) and that means that it’s a collection of tools related to the task of writing programs. So there’s a lot of stuff that will show up on your screen. I’ll cover the important ones to be aware of here; don’t panic if you see some additional stuff on my screen and you don’t have it on yours. I do a lot of development in here, so I’ve moved some stuff around for convenience. You’ll be able to see the most important stuff right away, and at another point, I’ll describe what you can do to switch things around. Don’t worry, it’s not likely that you’ll hurt anything by doing this.

Across the top is a typical menu bar. File, Edit, View, etc… all things we see in most of the programs on a computer. Below that is a toolbar with a set of icons. Initially you’ll see ones you recognize, like new, open, save and the undo and redo buttons. Next to that you’ll see a couple of drop-downs. Once will probably say “Debug”, the next will say “Any CPU”. Then you’ll have a Play button (a green arrow on my screenshot) and the word “Start”. And then there will be some more icons. The biggest one to be aware of is that Play / Start button. We’ll use this to actually run our first program. Over to the right of the screen, you’ll see a panel called “Solution Explorer”. You may also see a tab for “Team Explorer” and “Properties”. You can switch tabs if you’d like just to see what’s in them, but make sure you’re back on Solution Explorer when you’re done.

If that panel looks like the next image, you can click and drag the “Properties Tab” down; you’ll see a little set of icons appear, shaped like a plus. Drag over the lowest box, and it’ll separate so you can see it AND the Solutions / Team Explorer tabs separately.

On the left side of the screen, you’ll see a panel labelled “Toolbox”. That’s something we’ll cover later. At the bottom of the screen you’ll see “Output” with two tabs. One is called “Output” and the other is “Error List”. You might see some more tabs, too, but again, we’ll worry about that all later.

Finally, smack in the middle of the screen, you’ll see a window labelled “Program.cs” and have the results of a cat running across your keyboard… no, not really. You’ll see a bunch of text with some different colors and a series of numbers down the left side.

This is called the source code of your program. If you have a solution that has lots of libraries and files to it, you’ll see more tabs open across the top bar over time; but for now, we’ll just focus on what’s here.

The numbers on the left side of this window are actually line numbers. If you’re writing a program and something fails, this will help you to find where your mistake is.

Lines 1 – 5 on my example start with the word “using” followed by a few more words, and then a semi-colon. These are usually called “directives” or sometimes “includes”. Essentially, this is a collection of libraries of common code that your application may (or will) need. They’ll probably all look kind of dim-colored; that indicates that we aren’t actually using any of them just yet. This program will only really use one, but we can leave this as is.

Next, you’ll see the word “namespace” followed by “HelloWorld”. A namespace is a sort of container used for coding. We’ll get into more detail on that later as well.

Next, we see “class Program”. This the starting point of the actual application. We’ll discuss classes more soon, but something you’ll here in a lot of languages is the phrase “everything is a class” or “everything is an object”. What this really just means is that every part of a program written in these languages is essentially a sort of component that is used for operation. The initial class for C sharp is Program. That indicates that this is the program container.

Next, you’ll see “static void Main(string[] args)”. If you’re wondering what all this means, don’t worry, we’ll get to it when we’re ready. Lastly, you might notice a series of characters that look like this: { } Commonly they’re referred to as curly braces or brackets. Note how they’re placed. They indicate a sort of start and stop to a logical “container”. As we expand our skills, we’ll see their relevance quite quickly.

OK. What does this program do? Nothing! If you tried to run it now, it’d start and end… and chances are it would happen so fast you might not even see a window show up for it. If you do, it’ll be a sort of black box, and it’ll immediately disappear.

Let’s actually make something happen.

One Quite Note

Be aware that programming languages are typically case sensitive, especially when it comes to the names of functions, variables, and the like. Make sure you’re careful about names and spacing when you type things in, because quite often you can make a mistake by forgetting to make something uppercase. A key example will be the commands “Console.WriteLine” and “Console.ReadKey”, which we will use below. If you forget to capitalize the L in WriteLine, or the K in ReadKey, the program will NOT work.

One nice feature that helps with this is called IntelliSense. It’s a feature in Microsoft products (along with numerous others for programming) that will help you to select the right command and instructions. As you type, it will pop-up a list of possible values and try to guide you to the best choice. I’ll cover that in more depth at another point, but based on some feedback I received, I figured it was important to note that before we got too far into this.

Adding To The Code

In between the curly braces under the “static main” line, hit your enter or return key a few times. Go to the first line after the opening curly brace { and type in the following:

Console.WriteLine(“Hello, world!”);
Console.ReadKey();

Your program will look like this:

Go ahead and hit that “Start” button at the top of the screen.

Congratulations – you just wrote a program. It doesn’t do very much, but that’s not a problem. It actually did something. To exit, you can either hit the “Stop” button in Visual Studios, click the X on the windows to close it, or press any key on your keyboard and it’ll finish and close itself.

Down at the bottom of the screen, you’ll see in the “Output” window something like this:

This indicates that the program ran; when our programs get longer, we’ll see more information here that we can use to track through steps and do what’s called “debugging”. If you look at your code window, you’ll notice now that the first line “using System;” is now brighter than the other lines. That’s because we’re actually using code from that library. The Console.WriteLine and Console.ReadKey code is part of a general library called “System”.

We’ll dissect this program in more depth in a few articles. But for now, “Hello, world!”. Go ahead, and show it off! You made a computer program.