Recently, because of the need to analyze the engineering structure of VS, we all know that the solution file for Visual Studio ends in. sln
Not much nonsense to say, first look at the next simple SLN file structure
- Microsoft Visual Studio Solution File, Format Version 11.00
- # Visual Studio 2010
- Project ("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication1",
- "Consoleapplication1\consoleapplication1.csproj", "{cd680a35-b1db-4a3d-9073-2a604600d396}"
- Endproject
- Global
- Globalsection (solutionconfigurationplatforms) = Presolution
- Debug| x86 = debug|x86
- release| x86 = release|x86
- Endglobalsection
- Globalsection (projectconfigurationplatforms) = Postsolution
- {cd680a35-b1db-4a3d-9073-2a604600d396}. Debug| x86. Activecfg = debug|x86
- {cd680a35-b1db-4a3d-9073-2a604600d396}. Debug| x86. build.0 = debug|x86
- {cd680a35-b1db-4a3d-9073-2a604600d396}. release| x86. Activecfg = release|x86
- {cd680a35-b1db-4a3d-9073-2a604600d396}. release| x86. build.0 = release|x86
- Endglobalsection
- Globalsection (solutionproperties) = Presolution
- Hidesolutionnode = FALSE
- Endglobalsection
- Endglobal
The first line is the file description, there is a sentence format version 11.00 This sentence is the solution of the VS version
One of the things that starts with project is the project that the solution contains, as well as the fragment that has the end of the global beginning Endglobal, where there are some global configurations of the solution, and the content is understood at a glance, and there's not much to say here. Focus on the project fragment, this example contains only one project, did you find that project followed by a GUID, what is this?
Data found that the GUID here represents the project type, for example, "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC" above represents a C # project, followed by the project name and the project file path
The following is a list of the project types represented by the GUID
Files such as *.sln,*.csproj,*.vbproj used by Visual Studio represent a list of GUIDs for project types.
Useful for analyzing project information.
Project Type Description |
Project Type Guid |
Windows (C #) |
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} |
Windows (vb.net) |
{f184b08f-c81c-45f6-a57f-5abd9991f28f} |
Windows (Visual C + +) |
{8bc9ceb8-8b4a-11d0-8d11-00a0c91bc942} |
WEB Application |
{349C5851-65DF-11DA-9384-00065B846F21} |
Web Site |
{E24C65DC-7377-472B-9ABA-BC803B73C61A} |
Distributed System |
{f135691a-bf7e-435d-8960-f99683d2d49c} |
Windows Communication Foundation (WCF) |
{3d9ad99f-2412-4246-b90b-4eaa41c64699} |
Windows Presentation Foundation (WPF) |
{60dc8134-eba5-43b8-bcc9-bb4bc16c2548} |
Visual Database Tools |
{c252feb5-a946-4202-b1d4-9916a0590387} |
Database |
{a9ace9bb-cece-4e62-9aa4-c7e7c5bd2124} |
Database (Other project types) |
{4f174c21-8c12-11d0-8340-0000f80270f8} |
Test |
{3ac096d0-a1c2-e12c-1390-a8335801fdab} |
Legacy (2003) Smart Device (C #) |
{20D4826A-C6FA-45DB-90F4-C717570B9F32} |
Legacy (2003) Smart Device (vb.net) |
{Cb4ce8c6-1bdb-4dc7-a4d3-65a1999772f8} |
Smart Device (C #) |
{4d628b5b-2fbc-4aa6-8c16-197242aeb884} |
Smart Device (vb.net) |
{68b1623d-7fb9-47d8-8664-7ecea3297d4f} |
Workflow (C #) |
{14822709-b5a1-4724-98ca-57a101d1b079} |
Workflow (vb.net) |
{D59BE175-2ED0-4C54-BE3D-CDAA9F3214C8} |
Deployment Merge Module |
{06a35ccd-c46d-44d5-987b-cf40ff872267} |
Deployment Cab |
{3ea9e505-35ac-4774-b492-ad1749c4943a} |
Deployment Setup |
{978C614F-708E-4E1A-B201-565925725DBA} |
Deployment Smart Device Cab |
{Ab322303-2255-48ef-a496-5904eb18da55} |
Visual Studio Tools for Applications (VSTA) |
{a860303f-1f3f-4691-b57e-529fc101a107} |
Visual Studio Tools for Office (VSTO) |
{BAA0C2D2-18E2-41B9-852F-F413020CAA33} |
SharePoint Workflow |
{F8810ec1-6754-47fc-a15f-dfabd2e3fa90} |
XNA (Windows) |
{6d335f3a-9d43-41b4-9d22-f6f17c4be596} |
XNA (XBox) |
{2df5c3f4-5a5f-47a9-8e94-23b4456f55e2} |
XNA (Zune) |
{d399b71a-8929-442a-a9ac-8bec78bb2433} |
SharePoint (vb.net) |
{ec05e597-79d4-47f3-ada0-324c4f7c7484} |
SharePoint (C #) |
{593B0543-81F6-4436-BA1E-4747859CAAE2} |
Silverlight |
{A1591282-1198-4647-A2B1-27E5FF5F6F3B} |
ASP. NET MVC Application |
{603c0e0b-db56-11dc-be95-000d561079b0} |
There is a GUID that is not listed in the list you may often encounter, that is the solution folder, its type ID is "2150e333-8fdc-42a3-9474-1a3956d46de8"
How do I get the content of the solution?
Here I use the regular expression, the following is the GUID, the naming rule, the relative path of the expression
- public class Regexexpressionconst
- {
- <summary>
- GUID regular expression, format FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
- </Summary>
- Public const string guidexp = @ "\w{8}-(\w{4}-) {3}\w{12}";
- <summary>
- matching [project file naming]
- </Summary>
- Public const string projectext = @ "[a-z][\s\.\-\w]+";
- <summary>
- Match [relative path]
- </Summary>
- Public const string relativepathext = @ "(\ \?" ( [A-z] [\s\.\-\w]+]) + ";
- }
The following is the combination of these expressions, the following is the combination of regular expressions used to match the project in the SLN
- var projectregexexp = string. Format ("project\\ (\" {{{0}}}\ "\ \) \\s*=\\s*\" {1}\ "\\s*,\\s*\" {2}\ "\\s*,\\s*\ " {{3}}}\ "",
- Regexexpressionconst.guidexp, Regexexpressionconst.projectext, Regexexpressionconst.relativepathext, REGEXEXPRESSIONCONST.GUIDEXP);
Gets the name of the project file, the project file path, the type of project file, and also defines a new entity for convenient storage operations
- var projectpropertymodels = new List<projectpropertymodel> ();
- var projectreg = new Regex (Projectregexexp, regexoptions.compiled | Regexoptions.ignorecase);
- var projectcontexts = projectreg.matches (filecontent);
- foreach (Var projectcontext in projectcontexts)
- {
- var projectpropertymodel = new Projectpropertymodel ();
- var projectcontextProjectcontextarr = projectcontext.tostring (). Split (new string[]{"="}, stringsplitoptions.removeemptyentries);
- Projectpropertymodel.projecttypeid = new Regex (REGEXEXPRESSIONCONST.GUIDEXP). Match (Projectcontextarr[0]). ToString (). Trim ();
- var projectvaluearr = projectcontextarr[1]. Split (new string[] {","}, Stringsplitoptions.removeemptyentries);
- projectpropertymodel.projectname = projectvaluearr[0]. Replace ("\" "," "). Trim ();
- Projectpropertymodel.projectrelativepath = projectvaluearr[1]. Replace ("\" "," "). Trim ();
- Projectpropertymodel.projectid = projectvaluearr[2]. Replace ("\" {"," "). Replace ("}\", "" "). Trim ();
- Projectpropertymodel.projectabsolutepath = Path.Combine (Slnfolderpath, Projectpropertymodel.projectrelativepath);
- Projectpropertymodels.add (Projectpropertymodel);
- }
- <summary>
- Project file properties
- </Summary>
- public class Projectpropertymodel
- {
- <summary>
- Project Type ID
- </Summary>
- public string Projecttypeid {get; set;}
- <summary>
- Project name
- </Summary>
- public string ProjectName {get; set;}
- <summary>
- Project relative path
- </Summary>
- public string Projectrelativepath {get; set;}
- <summary>
- Project Absolute Path
- </Summary>
- public string Projectabsolutepath {get; set;}
- <summary>
- Project Unique identification
- </Summary>
- public string ProjectID {get; set;}
- }
With the name of the project file, the project file path, the type of project files, let us parse the project file now
Project documents everyone open their computer to *.csproj this end of the file to see it, this is not affixed, too long
Said parsing the project file parsing here has to mention Microsoft.Build.Evaluation.ProjectCollection, this collection can directly load a project into the collection, and return a project
- ProjectCollection pc = new ProjectCollection ();
- Project _project = pc. Loadproject (Projectfilepath)
Here we can easily get the contents of the project file.
- Assembly folder
- _project.directorypath
- Get assembly Name
- _project.getpropertyvalue ("AssemblyName");
- Get the Post-compilation folder
- _project.getpropertyvalue ("TargetDir");
- Get the post-compilation path
- _project.getpropertyvalue ("TargetPath");
- Get all referenced items
- _project.allevaluateditems.where (e => e.itemtype = = "Reference")
- Get all compiled items
- _project.allevaluateditems.where (e => e.itemtype = = "Compile")
- Get all Pages
- _project.allevaluateditems.where (e => e.itemtype = = "page")
- Get Other Items
- _project.allevaluateditems.where (e => e.itemtype = = "None")
Here is a list of some common items, in more detail you can directly view Http://technet.microsoft.com/zh-cn/microsoft.build.evaluation.project (v=vs.90)
Oh, with these things our entire engineering structure is not all there, the following can do what we want to do.
Engineering structure resolution for Visual Studio