1
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 和路径。名称、guid 和路径使用

Type.GetType().GetProperty()

我需要解析 ProjectDependencies 选项卡。我想知道是否可以类似地获得 ProjectDependencies 值?

也欢迎任何其他解决方案

提前致谢!!

4

1 回答 1

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);
            }
        }

这段代码做到了。

谢谢。

于 2012-09-10T14:35:46.790 回答