Solution (.sln) file

Original: Solution (the .sln) File

MSDN VS2008 and VS2010 presentation on the .sln file (solution file) in English only, now translated for the reader, want to help you. The limited level of the text will inevitably be wrong, welcome to correct me, Bese ~

Visual Studio solution is used in the organizational structure of the project. His role is similar to Windows VB6.0 in the program group (.vbg) files as well as in VC6.0 project workspace (.dsw) files. Solution status information items stored in the .sln file (the file is text-based, but is shared) and .suo file (the file is binary, and the solution is optional) in. For more information on .suo please see the solution user-selectable .suo file .

If your VSPackage due referenced in the .sln file and load, then the compiler environment calls ReadSolutionProps read .sln file.

.sln file contains text-based information, the compiler environment through information to find his references and loaded into the persistent data and VSPackages project. When a user opens a persistent information solutions when included in the compilation environment by preSolution .sln file, Project, postSolution information about loading solutions, projects included in the solution as well as any and solutions linked.

Each project file contains additional information, compilation environment by reading the information needed for the project in the project to complete it. Data Persistence is controlled by the project; it is generally not included in the data file .sln. Although you may be interested in the item information into the .sln file. For more information please refer to Project Persistence and Opening the Items Project and Saving .

Solution content files

.sln files are composed of several parts of the following code shown in FIG configuration, he is saved in the bottom of the solution browser. For more information about resolving the comment section of the program, see Extending Solution Explorer .

 

 

   1:  Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Project1", "Project1.vbproj", "{8CDD8387-B905-44A8-B5D5-07BB50E05BEA}"
   2: EndProject
   3:  Global
   4: GlobalSection (SolutionNotes) = postSolution
   5:         Name1 = Note2
   6:         Issue1 = N
   7:         Text1 = This is a shared note.
   8:         Name2 = Note3
   9:         Issue2 = N
  10:         Text2 = This is also a shared note. The second of two shared notes.
  11: NumNotes = 2
  12:    EndGlobalSection
  13:    GlobalSection(SolutionConfiguration) = preSolution
  14:         ConfigName.0 = Debug
  15:         ConfigName.1 = Release
  16:    EndGlobalSection
  17:    GlobalSection(ProjectDependencies) = postSolution
  18:    EndGlobalSection
  19:    GlobalSection(ProjectConfiguration) = postSolution
  20:     {8CDD8387-B905-44A8-B5D5-07BB50E05BEA}.Debug.ActiveCfg = Debug|.NET
  21:     {8CDD8387-B905-44A8-B5D5-07BB50E05BEA}.Debug.Build.0 = Debug|.NET
  22:     {8CDD8387-B905-44A8-B5D5-07BB50E05BEA}.Release.ActiveCfg = Release|.NET
  23:     {8CDD8387-B905-44A8-B5D5-07BB50E05BEA}.Release.Build.0 = Release|.NET
  24:    EndGlobalSection
  25:    GlobalSection(ExtensibilityGlobals) = postSolution
  26:    EndGlobalSection
  27:    GlobalSection(ExtensibilityAddIns) = postSolution
  28:    EndGlobalSection
  29:  EndGlobal

 

 

Compiler environment to perform the following sequence of work to load solutions

1. Compile the global environmental statement read .sln file and process all marked preSolution statement. In the foregoing example, such a statement:

 

 

   1:    GlobalSection(SolutionConfiguration) = preSolution
   2:         ConfigName.0 = Debug
   3:         ConfigName.1 = Release

 

When the compiler environment read GlobalSection ( 'name') mark, he will name mapped to VSPackage through the registry. Keyword name should be in the registry under [HKLM / <Application ID Registry Root> / SolutionPersistence] directory. The default value of the key is written VSPackage directory Package GUID (REG_SZ) of.

2. When the environmental load VSPackage for IVsPersistSolutionProps interface calls QueryInterface VSpackage, and the method by calling ReadSolutionProps data file, so VSPackage capable of storing data. Compilation environment for each place of preSolution repeat the operation as above.

3. Compile the project's environmental looping through the module. Well, here's a project (let us analyze)

 

 

   1:  Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Project1",
   2:  "Project1.vbproj", "{8CDD8387-B905-44A8-B5D5-07BB50E05BEA}"
   3: EndProject

 

Item globally unique identifier (GUID) included in the above code, and item type unique globally unique identifier (GUID). This information is used to find the compiler environment project file or files that you love belongs solutions, as well as those of any project requires a specific VSPackage. Globally Unique Identifier (GUID) of the project is delivered to IVsProjectFactory used to load and special VSPackage related projects, then the project is loaded. In the above code is loaded VSPackage is Visual Basic.

 

Each project there is a unique project instance ID, the only way this project in order to be his project requires the use of other solutions. Ideally, if the solutions and projects under source code control, the path and the path of the project should be relevant solutions. When the solution is first loaded, the project file can not exist in the user's computer. The project files are stored in file services and solutions related files by this method is relatively simple to find the project file or copy the project files to the user's computer. And then copy the required files to load the rest of the project build environment.

4. Load each project file based on information compiled environment .sln files included in the project. Level project itself good filler items and load any embedded project.

5. Then compile environmental performance are marked as those of the global statement postSolution. Below is an example of the above code snippet.

 

 

   1: GlobalSection (SolutionNotes) = postSolution
   2:         Name1 = Note2
   3:         Issue1 = N
   4:         Text1 = This is a shared note.
   5:         Name2 = Note3
   6:         Issue2 = N
   7:         Text2 = This is also a shared note. The second of two shared notes.
   8: NumNotes = 2
   9:    EndGlobalSection

 

As this case above, there are two in the .sln file sharing note.Note1 not included in the file, as he marked as shared. His content on .suo file. Each statement has a name and a value consisting of entries each note is one to one. Read more about implementing solutions, please see Note Extending Solution Explorer .

6. Finally .sln file is finished, the solution is displayed in Solution Explorer and allow the user's operation.

 

If any VSPackage about the project fails to load,  OnProjectLoadFailure method will be called and each solution in the project will try to cancel the change in the loading process. Parsing errors, to collect information about the solution files and build environment as much as possible to display a dialog box warning the solution has been destroyed.

 

When the solution is saved or closed QuerySaveSolutionProps method will be called and passed to the existence of those who need to save changes to the .sln file hierarchy check solution. In VSQUERYSAVESLNPROPS passed into QuerySaveSolutionProps a null value indicating that this information will be saved. If the information indicates that the value is not empty saved is a special project, depending on IVsHierarchy Interface

 

If the information is saved IVsSolutionPersistence interface will be directed SaveSolutionProps invoked method. Then WriteSolutionProps method will be called compiler environment, this method is used to test and from IPropertyBag interface corresponds to the name and the value of the relevant information into the .sln file.

 

In order to test from IPropertyBag whether the interface is saved SaveSolutionProps and WriteSolutionProps object is called recursively build environment, until all changes are written into the .sln file. In this way we can ensure that the information solutions can be saved and next time you can successfully open the solution.

 

Each loaded VSPackage are listed to see if there is a need to save something .sln file. Registration code is only required when loaded. Compiler environment knows all the loaded package, because when saving solutions when they were recorded.

 

Only .sln contains preSolution and postSolution of entry. No similar statement in .suo file because the correct solution needs to be loaded. .suo file contains the user's option, such as personal comments, which do not need to be shared or source control.

Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2012/08/19/2646295.html

Guess you like

Origin blog.csdn.net/weixin_33901926/article/details/93495176