Creating a Solution

To create a solution, you first create a project. Because projects can’t be loaded independently of a solution within Visual Studio, creating a project causes a solution to be created at the same time.


Note

There actually is a way to create a blank, or empty, solution without also creating a project. While creating a new project, if you expand the Other Project Types node that appears in the Installed Templates list, you will see a category for Visual Studio Solutions. This contains a Blank Solution template. Blank solutions are useful when you need to create a new solution to house a series of already existing projects; the blank solution obviates the need to worry about an extra, unneeded project being created on disk.


Launch the New Project dialog box by using the File menu and selecting the New, Project option (shown in Figure 4.1).

Image

FIGURE 4.1 The File, New, Project menu.

The New Project dialog box is displayed with defaults for the project name, location, and solution name (see Figure 4.2). We take a detailed look at the various project types offered there when we discuss projects later in this chapter. Notice that a Solution Name field is displayed at the bottom of the dialog box. In this field, you can customize the name of your solution before you create it. Clicking OK at this point does two things: a project of the indicated type and name is created on disk (at the location specified), and a solution, with links to the project, is created on disk using the provided name.

Image

FIGURE 4.2 The New Project dialog box.

If you have selected something other than the Blank Solution project type, Visual Studio now displays the newly created solution and project in the Solution Explorer window. (You will learn about Solution Explorer in depth in Chapter 5, “Browsers and Explorers.”) In effect, Visual Studio has created the solution hierarchy shown in Figure 4.3.

Image

FIGURE 4.3 A simple solution hierarchy.

Assuming that you have accepted the default locations and left the Create Directory for Solution box checked on a Universal App solution, the physical directory/file structure is created, as shown in Figure 4.4.

Image

FIGURE 4.4 The solution file hierarchy.

In this example, the first App1 folder holds the solution file and has a subfolder for each project. The second App1 folder contains the new project. The source files are placed in this folder, and any compiled output files sit underneath the bin directory and then under the specific build configuration (for example, Debug or Release). This particular example is unique to the Universal App project type; each project type can have its own unique approach to structuring its file hierarchy.


Caution

By default, the solution is named after the project. There is potential for confusion here because you now have two folders/entities named App1. One refers to the solution; the other refers to the project. This is not an ideal way to physically organize your code on disk. It is recommended that you give the solution a unique name during the project creation process by simply overriding the default name given in the Solution Name field (see Figure 4.2).


The Solution Definition File

Visual Studio stores solution information inside two separate files: a solution definition file and a solution user options file. For the preceding example, a solution definition file (App1.sln) and a solution user options file (App1.suo) were created.

The solution definition file is responsible for actually describing any project relationships in the solution and for storing the various solution-level attributes that can be set. The solution user options file persists any customizations or changes that you, as a Visual Studio user, might have made to the way the solution is displayed within the IDE (such as whether the solution is expanded or which documents from the solution are open in the IDE). In addition, certain source control settings and other IDE configuration data are stored here.

The solution user options file is, by default, marked as a hidden file and is stored within a hidden folder; its content is actually binary. Because its internal structure is not publicly documented, we do not attempt to dissect it here. The solution definition file, however, is simply a text file. Listing 4.1 shows the file content for a fairly complex sample solution.

LISTING 4.1 Sample Solution File


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contoso.Fx.Integration",
"ClassLibrary1Contoso.Fx.Integration.csproj", "{DA0BA585-76C1-4F5E-B7EF-R57254E185BE4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contoso.Fx.Common",
"Contoso.Fx.CommonContoso.Fx.Common.csproj", "{A706BCAC-8FD7-4D8A-AC81-R249ED61FDE72}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contoso.Fx.Analysis",
"Contoso.Fx.AnalysisContoso.Fx.Analysis.csproj", "{EB7D75D7-76FC-4EC0-A11E-2B54849CF6EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contoso.Fx.UI",
"Contoso.Fx.UIContoso.Fx.UI.csproj", "{98317C19-F6E7-42AE-AC07-72425E851185}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Architecture Models",
"Architecture Models", "{60777432-3B66-4E03-A337-0366F7E0C864}"
    ProjectSection(SolutionItems) = postProject
        ContosoSystemDiagram.sd = ContosoSystemDiagram.sd
    EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contoso.UI.WindowsForms.
OrderEntry", "Contoso.UI.WindowsForms.OrderEntryContoso.UI.WindowsForms.
OrderEntry.csproj", "{49C79375-6238-40F1-94C8-4183B466FD79}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Class Libraries", "Class
Libraries", "{E547969C-1B23-42DE-B2BB-A13B7E844A2B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Controls", "Controls",
"{ED2D843C-A708-41BE-BB52-35BFE4493035}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {DA0BA585-76C1-4F5E-B7EF-57254E185BE4}.Debug|Any CPU.ActiveCfg = Debug|
        Any CPU
        {DA0BA585-76C1-4F5E-B7EF-57254E185BE4}.Debug|Any CPU.Build.0 = Debug|
        Any CPU
        {DA0BA585-76C1-4F5E-B7EF-57254E185BE4}.Release|Any CPU.ActiveCfg = Release
        |Any CPU
        {DA0BA585-76C1-4F5E-B7EF-57254E185BE4}.Release|Any CPU.Build.0 = Release|
        Any CPU
        {A706BCAC-8FD7-4D8A-AC81-249ED61FDE72}.Debug|Any CPU.ActiveCfg = Debug|
        Any CPU
        {A706BCAC-8FD7-4D8A-AC81-249ED61FDE72}.Debug|Any CPU.Build.0 = Debug|
        Any CPU
        {A706BCAC-8FD7-4D8A-AC81-249ED61FDE72}.Release|Any CPU.ActiveCfg = Release
        |Any CPU
        {A706BCAC-8FD7-4D8A-AC81-249ED61FDE72}.Release|Any CPU.Build.0 = Release
        |Any CPU
        {EB7D75D7-76FC-4EC0-A11E-2B54849CF6EB}.Debug|Any CPU.ActiveCfg = Debug| Any
        CPU
        {EB7D75D7-76FC-4EC0-A11E-2B54849CF6EB}.Debug|Any CPU.Build.0 = Debug|
        Any CPU
        {EB7D75D7-76FC-4EC0-A11E-2B54849CF6EB}.Release|Any CPU.ActiveCfg =
        Release |Any CPU
        {EB7D75D7-76FC-4EC0-A11E-2B54849CF6EB}.Release|Any CPU.Build.0 = Release
        |Any CPU
        {98317C19-F6E7-42AE-AC07-72425E851185}.Debug|Any CPU.ActiveCfg = Debug|
        Any CPU
        {98317C19-F6E7-42AE-AC07-72425E851185}.Debug|Any CPU.Build.0 = Debug|
        Any CPU
        {98317C19-F6E7-42AE-AC07-72425E851185}.Release|Any CPU.ActiveCfg =
        Release |Any CPU
        {98317C19-F6E7-42AE-AC07-72425E851185}.Release|Any CPU.Build.0 = Release
        |Any CPU
        {49C79375-6238-40F1-94C8-4183B466FD79}.Debug|Any CPU.ActiveCfg = Debug|
        Any CPU
        {49C79375-6238-40F1-94C8-4183B466FD79}.Debug|Any CPU.Build.0 = Debug|
        Any CPU
        {49C79375-6238-40F1-94C8-4183B466FD79}.Release|Any CPU.ActiveCfg =
       Release |Any CPU
        {49C79375-6238-40F1-94C8-4183B466FD79}.Release|Any CPU.Build.0 =
        Release |Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(NestedProjects) = preSolution
        {ED2D843C-A708-41BE-BB52-35BFE4493035} = {E547969C-1B23-42DE-B2BB-A13B7E844A2B}
        {EB7D75D7-76FC-4EC0-A11E-2B54849CF6EB} = {E547969C-1B23-42DE-B2BB-A13B7E844A2B}
        {A706BCAC-8FD7-4D8A-AC81-249ED61FDE72} = {E547969C-1B23-42DE-B2BB-A13B7E844A2B}
        {DA0BA585-76C1-4F5E-B7EF-57254E185BE4} = {E547969C-1B23-42DE-B2BB-A13B7E844A2B}
        {98317C19-F6E7-42AE-AC07-72425E851185} = {ED2D843C-A708-41BE-BB52-35BFE4493035}
    EndGlobalSection
EndGlobal


At the beginning of the file are references to the projects that belong to the solution. The references contain the project’s name, its globally unique identifier (GUID), and a relative path to the project file itself (more on project files in a bit):

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contoso.Fx.Integration",
"ClassLibrary1Contoso.Fx.Integration.csproj", "{DA0BA585-76C1-4F5E-B7EF-R57254E185BE4}"
EndProject

You can also see some of the various configuration attributes applied to the solution; the Debug and Release settings, for instance, show up here. Note that this project contains several solution folders: Architecture Models, Class Libraries, and Controls. They are represented in the solution file in much the same way as projects. In fact, the only difference is that they do not have a relative file path associated with them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset