Beispiel #1
0
        private static void EvaluateGlobalSection(this VsSolutionFile sln, string[] block)
        {
            var sectionNameAndPrePost = block[0].Split('=');
            var section = new VsSolutionFileGlobalSection(
                sectionNameAndPrePost[0].Substring(15, sectionNameAndPrePost[0].Length - 15 - 2),
                sectionNameAndPrePost[1] == " preSolution" ? PrePostSolution.preSolution : PrePostSolution.postSolution);

            for (int i = 1; i < block.Length - 1; i++)
            {
                var values = block[i].Split('=');
                section.Items.Add(values[0].Substring(2).Trim(), values[1].Trim());
            }

            if (section.Name == "ExtensibilityGlobals")
            {
                sln.SolutionId = Guid.Parse(section.Items["SolutionGuid"]);
            }

            if (section.Name == "NestedProjects")
            {
                foreach (var item in section.Items)
                {
                    sln.Projects[Guid.Parse(item.Key)].ParentPoject = Guid.Parse(item.Value);
                }
            }

            if (sln.GlobalSections.ContainsKey(section.Name))
            {
                sln.GlobalSections.Remove(section.Name);
            }
            sln.GlobalSections.Add(section.Name, section);
        }
        internal static string[] GetLines(this VsSolutionFileGlobalSection gs)
        {
            var text = new List <string>();

            text.Add($"\tGlobalSection({gs.Name}) = {gs.SectionPrePost}");
            foreach (var item in gs.Items)
            {
                text.Add($"\t\t{item.Key} = {item.Value}");
            }
            text.Add($"\tEndGlobalSection");

            return(text.ToArray());
        }
        internal static void Add(this Dictionary <string, VsSolutionFileGlobalSection> list, string name, PrePostSolution prePost, string[][] values = null)
        {
            var item = new VsSolutionFileGlobalSection(name, prePost);

            if (values != null)
            {
                foreach (var value in values)
                {
                    item.Items.Add(value[0], value[1]);
                }
            }

            list.Add(item.Name, item);
        }
        internal static void RebuildSectionNestedProjects(this VsSolutionFile sln)
        {
            if (sln.GlobalSections.ContainsKey("NestedProjects"))
            {
                sln.GlobalSections.Remove("NestedProjects");
            }
            var nestedProjectsSection = new VsSolutionFileGlobalSection("NestedProjects", PrePostSolution.preSolution);

            foreach (var project in sln.Projects)
            {
                if (project.Value.ParentPoject != Guid.Empty)
                {
                    nestedProjectsSection.Items.Add(project.Key.ToStingVSFormat(), project.Value.ParentPoject.ToStingVSFormat());
                }
            }

            if (nestedProjectsSection.Items.Count > 0)
            {
                sln.GlobalSections.Add(nestedProjectsSection.Name, nestedProjectsSection);
            }
        }