Join Walt Ritscher for an in-depth discussion in this video Creating a new project, part of Visual Studio 2015 Essentials 03: Exploring Projects and Solutions.
- View Offline
- In this video I'll look at how to create a new project and explore the correlation between new projects and new solutions. This is not the video to explore the many kinds of project types available in Visual Studio. That comes later in the course. Here we look at what happens when you create a project from the Visual Studio IDE. I'm inside Visual Studio. To create a new project, I will choose the File menu, and then I'll choose this top menu item Project. That opens the New Project dialog. Along the left side of the screen are a number of templates.
You can see that they're affiliated with a programming language usually. Here's one for Visual C#. There's one for Visual Basic and many other languages. When I open the Visual C# node, I can see different types of projects. There's Windows projects, and web projects, and so on. When I go to this Windows menu I can see even further that there's a Windows Form application, a WPF application, and the one that I want for this project, the Console application. I won't accept the default name. I'll call this one ConsoleApp, and I will also select a different location.
If I don't choose a location, it'll use a default location which is here. This is the default. It's in your documents folder, Visual Studio 2015, Projects folder. I don't want to put my project there so I'll click on browse, choose my desktop, open my Video folder, and then choose this Create Projects subfolder. Next I'll choose Select Folder, and then click OK. Now before I do that, notice that it says here Create directory for a solution.
Keep that in mind for a second. Let's see what happened inside Visual Studio. Well it's obvious that it opened a code file. I can see a tab here and at the top of the tab it says Program.cs. I can see my C# code here. But more important for this chapter is what's happening over here in the Solution Explorer. There are two nodes with the same name. This top-level node represents the solution. Remember that a solution can contain multiple projects.
This solution has a single C# child project and I can see that represented here. Now here's a key point. Visual Studio always creates a solution for a new project. Since I didn't specify a name for the solution, it used the same name as the project. Let's see what's inside this C# project. That's for configuring different properties for the project. There's a reference section for setting references to external libraries. There's a few of the items in there. There's also an App.config file and the Program.cs file we saw a few minutes ago.
Here is the folder on my hard drive that I saved the project into. Now you'll see that there's a ConsoleApp folder here, and remember that I checked that checkbox that said Create a directory for the solution? So that created this SLN file in a separate folder and then the actual project is contained in this folder. And because the solution and the project had the same name, these two folders have the same name. Now let's look inside this ConsoleApp project folder and here I'll see the physical file for Program.cs.
There's also the C# project file itself, the AppConfig file, a folder for some of the Property settings, and two folders that are created by the Compiler; the bin folder and the obj folder. I'm back inside Visual Studio. I'm going to close this solution and create a brand new project. I'll close the solution and I'll start fresh. Now let me show you something interesting. Remember that I said that Visual Studio always creates a solution? Let's take a look at that New menu.
It says New, Project, New, Website, New, Team Project, a New, File and I can even use this last one Project From Existing Code. But do you see where it says New Solution anywhere in this menu? No. It doesn't say that in the New Project dialog. Well, it does, but you have to look closely. This is one of those peculiar quirks of Visual Studio that sometimes confuses new users. You'll say I want to create a new solution and there is no place to create a new solution. Well, let's look more closely.
It's down here but kind of obscure. Here I can specify the name of the project and I can also specify the name of the solution. This is the only place where you can do that. So let's try this again. I'm going to make a VB project this time. Go down here, choose Windows, choose Console. I'll call this one ConsoleApp the same as I did before. I'll rename the solution and I'll call it CreateNewProject. I'll continue to create a directory for the solution. Now some developers like to keep their solution and their project files in the same folder, but most of the developers I know prefer to have one folder for the solution and subfolders for all of the child projects.
So I'll leave this one checked and then I'll click on OK. This time I've got a code window over here called Module1.vb. You can see the code is in Visual Basic over here. And if I go over to my Solution Explorer, I see that I have two separate names now. The solution is called CreateNewProject, and the VB application is called ConsoleApp. I'd like to show you some more settings inside that dialog so let's open that again. Go up here and choose New, Project.
Because I'm inside an existing solution, I have a choice of where the new project goes. I can create a brand new solution, or I can add to the existing solution. I'll choose this second item, Add to solution. I'll call this one... I'm going to create a, let's do a WPF application. This is still in Visual Basic. Yeah, I'll leave it there and then I'll click on OK and there you have it. I now have a VB ConsoleApp and a VB WPF app inside the same solution.
Let's try that one more time. I'll go over here to New, Project, and this time I'll say Create in new instance. Let's see what that does, and I'll switch back to C# for this example. Windows, I'll do a Windows Forms application this time. I'll go ahead and leave the names at the default for both the solution and the project. Same location here, and when I click OK, Visual Studio launches another instance of Visual Studio. So now I have one instance of Visual Studio with this solution, and I'll switch over here and there's my other instance of Visual Studio with my old solution.
Now that you know how to create a project and its affiliated solution, let's explore how to create a blank solution.