Engineering structure resolution for Visual Studio

Source: Internet
Author: User
Tags visual studio 2010

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

  1. Microsoft Visual Studio Solution File, Format Version 11.00
  2. # Visual Studio 2010
  3. Project ("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication1",
  4. "Consoleapplication1\consoleapplication1.csproj", "{cd680a35-b1db-4a3d-9073-2a604600d396}"
  5. Endproject
  6. Global
  7. Globalsection (solutionconfigurationplatforms) = Presolution
  8. Debug| x86 = debug|x86
  9. release| x86 = release|x86
  10. Endglobalsection
  11. Globalsection (projectconfigurationplatforms) = Postsolution
  12. {cd680a35-b1db-4a3d-9073-2a604600d396}. Debug| x86. Activecfg = debug|x86
  13. {cd680a35-b1db-4a3d-9073-2a604600d396}. Debug| x86. build.0 = debug|x86
  14. {cd680a35-b1db-4a3d-9073-2a604600d396}. release| x86. Activecfg = release|x86
  15. {cd680a35-b1db-4a3d-9073-2a604600d396}. release| x86. build.0 = release|x86
  16. Endglobalsection
  17. Globalsection (solutionproperties) = Presolution
  18. Hidesolutionnode = FALSE
  19. Endglobalsection
  20. 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

  1. public class Regexexpressionconst
  2. {
  3. <summary>
  4. GUID regular expression, format FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
  5. </Summary>
  6. Public const string guidexp = @ "\w{8}-(\w{4}-) {3}\w{12}";
  7. <summary>
  8. matching [project file naming]
  9. </Summary>
  10. Public const string projectext = @ "[a-z][\s\.\-\w]+";
  11. <summary>
  12. Match [relative path]
  13. </Summary>
  14. Public const string relativepathext = @ "(\ \?" ( [A-z] [\s\.\-\w]+]) + ";
  15. }

The following is the combination of these expressions, the following is the combination of regular expressions used to match the project in the SLN

    1. var projectregexexp = string. Format ("project\\ (\" {{{0}}}\ "\ \) \\s*=\\s*\" {1}\ "\\s*,\\s*\" {2}\ "\\s*,\\s*\ " {{3}}}\ "",
    2. 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

  1. var projectpropertymodels = new List<projectpropertymodel> ();
  2. var projectreg = new Regex (Projectregexexp, regexoptions.compiled | Regexoptions.ignorecase);
  3. var projectcontexts = projectreg.matches (filecontent);
  4. foreach (Var projectcontext in projectcontexts)
  5. {
  6. var projectpropertymodel = new Projectpropertymodel ();
  7. var projectcontextProjectcontextarr = projectcontext.tostring (). Split (new string[]{"="}, stringsplitoptions.removeemptyentries);
  8. Projectpropertymodel.projecttypeid = new Regex (REGEXEXPRESSIONCONST.GUIDEXP). Match (Projectcontextarr[0]). ToString (). Trim ();
  9. var projectvaluearr = projectcontextarr[1]. Split (new string[] {","}, Stringsplitoptions.removeemptyentries);
  10. projectpropertymodel.projectname = projectvaluearr[0]. Replace ("\" "," "). Trim ();
  11. Projectpropertymodel.projectrelativepath = projectvaluearr[1]. Replace ("\" "," "). Trim ();
  12. Projectpropertymodel.projectid = projectvaluearr[2]. Replace ("\" {"," "). Replace ("}\", "" "). Trim ();
  13. Projectpropertymodel.projectabsolutepath = Path.Combine (Slnfolderpath, Projectpropertymodel.projectrelativepath);
  14. Projectpropertymodels.add (Projectpropertymodel);
  15. }
  16. <summary>
  17. Project file properties
  18. </Summary>
  19. public class Projectpropertymodel
  20. {
  21. <summary>
  22. Project Type ID
  23. </Summary>
  24. public string Projecttypeid {get; set;}
  25. <summary>
  26. Project name
  27. </Summary>
  28. public string ProjectName {get; set;}
  29. <summary>
  30. Project relative path
  31. </Summary>
  32. public string Projectrelativepath {get; set;}
  33. <summary>
  34. Project Absolute Path
  35. </Summary>
  36. public string Projectabsolutepath {get; set;}
  37. <summary>
  38. Project Unique identification
  39. </Summary>
  40. public string ProjectID {get; set;}
  41. }

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

    1. ProjectCollection pc = new ProjectCollection ();
    2. Project _project = pc. Loadproject (Projectfilepath)

Here we can easily get the contents of the project file.

  1. Assembly folder
  2. _project.directorypath
  3. Get assembly Name
  4. _project.getpropertyvalue ("AssemblyName");
  5. Get the Post-compilation folder
  6. _project.getpropertyvalue ("TargetDir");
  7. Get the post-compilation path
  8. _project.getpropertyvalue ("TargetPath");
  9. Get all referenced items
  10. _project.allevaluateditems.where (e => e.itemtype = = "Reference")
  11. Get all compiled items
  12. _project.allevaluateditems.where (e => e.itemtype = = "Compile")
  13. Get all Pages
  14. _project.allevaluateditems.where (e => e.itemtype = = "page")
  15. Get Other Items
  16. _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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.