Analysis of Engineering Structure in Visual Studio

Source: Internet
Author: User

As we need to analyze the engineering structure of Vs, we all know that the solution file ending with. sln is.

Not to mention anything. First, check the structure of the next simple SLN file.

Microsoft Visual Studio solution file, format version 11.00
# Visual maxcompute 2010
Project ("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "consoleapplication1", "leleapplication1 \ 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. The format version 11.00 statement describes the vs version of the solution.

The project that starts with the project is the project included in the solution, and the segment that ends with endglobal starting with global. Here are some global configurations of the solution, which can be understood at a glance, I will not talk about it here. Focus on the project fragment. This example only contains one project. Have you found that the project is followed by a guid? What is this?

After checking the information, we found that the guid here represents the project type, for example, the above "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC" represents a C # project, followed by the project name and the project file path

The following is a table of engineering types represented by guid.

The *. sln, *. csproj, *. vbproj files used by Visual Studio represent the guid list of the project type.
It is 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-111089384-00065b846f21}
Web Site {E24C65DC-7377-472B-9ABA-BC803B73C61A}
Distributed System {F135691A-BF7E-435D-8960-F99683D2D49C}
Windows Communication Foundation (WCF) {3d9ad99f-2412-1166-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-108f80270f8}
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-b316-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}

One GUID is also frequently encountered in the list, that is, the solution folder. Its Type ID is "2150e333-8fdc-42a3-9474-1a3956d46de8"

How can I obtain the content of the solution?

Here I use a regular expression. The following is a guid, naming rule, and relative path expression.

Public class regexexpressionconst {// <summary> // The Regular Expression of guid, format FAE04EC0-301F-11D3-BF4B-00C04F79EFBC // </Summary> Public const string guidexp = @ "\ W {8}-(\ W {4}-) {3} \ W {12 }"; /// <summary> /// match [project file name] /// </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 a combination of these expressions. The following is the combination of regular expressions used to match the project in SLN.

var projectRegexExp = string.Format("Project\\(\"{{{0}}}\"\\)\\s*=\\s*\"{1}\"\\s*,\\s*\"{2}\"\\s*,\\s*\"{{{3}}}\"",   RegexExpressionConst.GuidExp, RegexExpressionConst.ProjectExt, RegexExpressionConst.RelativePathExt, RegexExpressionConst.GuidExp);

Obtain the project file name, project file path, and project file type. A new object is defined to facilitate storage operations.

VaR projectpropertymodels = new list <projectpropertymodel> (); var projecreg = new RegEx (projectregexexp, regexoptions. compiled | regexoptions. ignorecase); var projectcontexts = projecregulatory. matches (filecontent); foreach (VAR projectcontext in projectcontexts) {var projectpropertymodel = new projectpropertymodel (); var projectcontextarr = 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 attributes /// </Summary> public class projectpropertymodel {// <summary> /// project type ID /// </ summary> Public String projecttypeid {Get; set ;}//< summary> /// project name /// </Summary> Public String projectname {Get; set ;} /// <summary> // relative project path // </Summary> Public String projectrelativepath {Get; set ;} /// <summary> // absolute project path // </Summary> Public String projectabsolutepath {Get; set ;} /// <summary> /// unique project id /// </Summary> Public String projectid {Get; Set ;}}

 

With the name of the project file, the path of the project file, and the type of the project file, let's parse the project file.

Open the file that ends with *. csproj on your computer. It's too long.

The parsing Project File Parsing has to mention Microsoft. Build. Evaluation. projectcollection, which can directly load a project to the collection and return a project

ProjectCollection pc = new ProjectCollection();Project _Project = pc.LoadProject(projectFilePath)

Here we can easily get the content in the project file.

Assembly folder
_ Project. directorypath
Get Assembly name_project. getpropertyvalue ("assemblyname"); get the compiled folder _ project. getpropertyvalue ("targetdir"); get the compiled path _ project. getpropertyvalue ("targetpath"); get all referenced items _ project. allevaluateditems. where (E => E. itemtype = "Reference") obtain all the compilation project_project. allevaluateditems. where (E => E. itemtype = "compile") Get all pages _ project. allevaluateditems. where (E => E. itemtype = "page. allevaluateditems. where (E => E. itemtype = "NONE ")

Here list some common items, more detailed you can directly view the http://technet.microsoft.com/zh-cn/microsoft.build.evaluation.project (V = vs.90)

Well, if we have all these things in our entire project structure, we can do what we want.

 

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.