0
Project("{00000000-0000-0000-0000-000000000000}") = "Test Projects", "TestProjects", "{5FAF487E-B913-4D46-983E-CB13FDF36FCB}" 
EndProject 
Project("{11111111-1111-1111-1111-111111111111}") = "ProjPropHelperAPI", "ProjPropHelperAPI\ProjPropHelperAPI.vcxproj", "{22222222-2222-2222-2222-222222222222}" 
EndProject 
Project("{33333333-3333-3333-3333-333333333333}") = "ProjectPropertiesHelperAPI", "ProjectPropertiesHelperAPI\ProjectPropertiesHelperAPI.csproj", "{66666666-6666-6666-6666-666666666666}" 
    ProjectSection(ProjectDependencies) = postProject 
     {44444444-4444-4444-4444-444444444444} = {44444444-4444-4444-4444-444444444444} 
     {55555555-5555-5555-5555-555555555555} = {55555555-5555-5555-5555-555555555555} 
    EndProjectSection 
EndProject 

我可以讀出項目名稱,使用該解決方案的GUID和路徑提到to this question。名稱,guid和路徑使用解析ProjectDependency從.sln文件

Type.GetType().GetProperty() 

我需要解析ProjectDependencies選項卡。我想知道是否可以同樣獲得ProjectDependencies值?

任何其他解決方案也歡迎

在此先感謝!

回答

0
 var filePath = @"C:\Users\xyz\Documents\Visual Studio 2010\Projects\test\test.sln" 
     var slnLines = File.ReadAllLines(filePath); 
     var projGuid = new List<string>(); 
     for(var i=0; i<slnLines.Length; i++) 
     { 
      if (slnLines[i].Contains(@"ProjectSection(ProjectDependencies)")) 
       while (!slnLines[i+1].Contains("EndProjectSection")) 
       { 
        var temp = (slnLines[i+1].Split(new[]{'=', '\n', '\t', ' '},2,StringSplitOptions.RemoveEmptyEntries)); 
        if(temp.ElementAt(0) == temp.ElementAt(1)) 
         projGuid.Add(temp.ElementAt(0)); 
        i++; 
       } 
     } 

     using (var file = new StreamWriter(@"C:\Users\xyz\Desktop\Results.txt")) 
     { 
      foreach (var pGuid in projGuid) 
      { 
       file.WriteLine(pGuid); 
      } 
     } 

這段代碼做到了。

謝謝。