Join Walt Ritscher for an in-depth discussion in this video Introducing projects and solutions, part of Visual Studio 2015 Essential Training: 03 Exploring Projects and Solutions.
- You can't work in Visual Studio without encountering the Solution and Project concept. They are fundamental to the way Visual Studio loads and compiles projects. I'll explain the core concepts of these essential items in this video. Let's start with a concept of a Visual Studio Solution. At it's most fundamental, it is a file on your computer with the file extension .sln. When you start working on a code project, you open the Solution file. Stored within the file is the minimum version number of Visual Studio required to open the Solution.
Therefore if I have a Solution targeting Visual Studio 2010, and I try to open it in Visual Studio 2008, I'll see a compatibility error message. Also stored in the file is the preferred version of Visual Studio for this Solution. This is useful if you happen to have multiple versions of Visual Studio installed on your computer. When you open a Visual Studio 2015 Solution file, it opens in Visual Studio 2015. Other versions of the sln file open in their associated Visual Studio IDEs.
Also included in the Solution file is a list of projects. When the Solution is opened, Visual Studio loads every project in the list into the IDE and shows the projects in the Solution Explorer. I'll show you a couple of examples to clarify these concepts. I'll start by opening this TheSolutionFiles folder. Here is a Solution file. I can see the .sln extension. If you don't see the .sln extension on your computer, you'll need to enable the file extensions feature. On Windows 8, you can do that here in File Explorer by the checking this check-box.
When I uncheck this check-box you see that the .sln extension disappears and now it reappears. I have four Solution files in this folder. Each one is linked to a specific version of Visual Studio. You can see the version number in the upper right corner of the icon. Like most Microsoft products, there is the internal version number and the marketing version number. The number you see on the icon is the internal version number. I'll show you the published version in a few seconds. If I double click the file, Windows will open Visual Studio. I don't want to do that yet.
Instead, I'll open the files in my favorite text editor, Notepad ++. If you are following along, you can download a free copy of Notepad ++ or use another text editor. I'll select all the files, and then I'll right click and choose Edit with Notepad ++. Within this text file, you can see the information about which version of Visual Studio this file is affiliated with. Here is the preferred version of Visual Studio, and this also lists the minimum Visual Studio version.
You notice that each one of these files contains different information. Here's one for Visual Studio 2013. This is the one for Visual Studio 2010. And this is the one for Visual Studio 2008. These first two files are a more modern version of the sln file format. They include the minimum version number permitted to open the file. These other two files don't have that information. Now, I'll open these Solution files in Visual Studio. On my computer, I have Visual Studio 2015 and Visual Studio 2013 installed, so here's what should happen.
This file should open in Visual Studio 2015. This file is for Visual Studio 2013. You can see that here in the Visual Studio version. So, this one should open with Visual Studio 2013. This file is for Visual Studio 2010. I don't have that version installed on my computer, so it should open in Visual Studio 2015. That's because 2015 supports Solutions from 2010 and newer. Finally, what about this 2008 file? I don't have Visual Studio 2008 on this computer.
The file cannot be opened in either of my copies of Visual Studio, so I should see a compatibility upgrade dialogue. Now, let's see if that works as I said. Return back to the File Explorer and double click on this first sln file. As you can see, Visual Studio 2015 opens, and it loads my Solution. Now we'll try this icon. That's correctly opening it in Visual Studio 2013. There it is.
Next we'll try this one for Visual Studio 2010. It's correctly opening in the version 2015. And finally, I'll double click on this 2008 version. It's opening 2015, and now I get this dialogue that says, "Review Project and Solution Changes". Now it's telling me that there will be a one-way upgrade, and that it will automatically make changes to the following projects, this Empty4.sln file.
It also includes binary files like icons, images, and music files. There might be data files in the project. For example, a JSON file containing configuration information for your application. Plus, you'll find a lot of content files. For example, text files, HTML pages, CSS documents, and XMAL files. Each project will contain a unique list of items. Let me dig a little deeper into how the contents of the Project file are used in Visual Studio. Knowing how the information in the file is consumed by Visual Studio is valuable for understanding what is happening in Visual Studio when you code and compile.
There are two major actions that are performed with the information. The Load Action happens when you open the project in Visual Studio. The Build Action happens when you compile your code. When Visual Studio opens the Project file which is encoded in XML format, it parses the contents and populates tool windows with the contents of the file. All of the file and folder information is parsed and shown in the Solution Explorer tool window. The information in the reference section of the XML file is loaded into the Reference Tool window and also into a node in the Solution Explorer.
You can specify additional tasks to run before or after the compiler step. For example, before compiling, you could run a batch command or a powershell script. After the Build, you could run your automated test suite. Details about what is in the Project files and how to work successfully with projects and solutions is located in the other videos in this chapter. As you progress through the course, you'll learn about the other tool windows and more about the Build process too.