예제 #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);
        }
예제 #2
0
        public static VsSolutionFile Open(string filePath)
        {
            var sln = new VsSolutionFile(filePath);

            sln.ReadSolutionFile();

            return(sln);
        }
        public static string SaveAs(this VsSolutionFile sln, string filepath)
        {
            var text = new List <string>();

            System.IO.File.WriteAllLines(filepath, sln.GetSolutionsFileLines());

            return(filepath);
        }
        internal static string[] GetHeader(this VsSolutionFile solutionFile)
        {
            var text = new List <string>();

            text.AddRange(GetVsSolutionHeaderFormatVS12());
            text.AddRange(GetVsSlutionHeaderExtention());

            return(text.ToArray());
        }
        internal static string[] GetSolutionsFileLines(this VsSolutionFile sln)
        {
            var text = new List <string>();

            text.AddRange(sln.GetHeader());
            text.AddRange(sln.GetProjects());
            text.AddRange(sln.GetGlobalSections());

            return(text.ToArray());
        }
        internal static string[] GetProjects(this VsSolutionFile sln)
        {
            var text = new List <string>();

            foreach (var p in sln.Projects)
            {
                text.AddRange(p.Value.GetProjectItemLines());
            }

            return(text.ToArray());
        }
예제 #7
0
        internal static VsSolutionFile ReadSolutionFile(this VsSolutionFile sln)
        {
            var filePath = sln.SolutionFolder + "/" + sln.Filename;

            var lines = System.IO.File.ReadAllLines(filePath);
            var block = new List <string>();

            var isHeader        = true;
            var isProject       = false;
            var isGlobalSection = false;
            var line            = 0;

            while (line < lines.Length)
            {
                // Header
                if (isHeader && lines[line].StartsWith("Project(\"{"))
                {
                    sln.EvaluateHeader(block.ToArray());
                    isHeader = false;
                }
                // projects
                if (!isHeader && lines[line].StartsWith("Project(\"{"))
                {
                    block     = new List <string>();
                    isProject = true;
                }
                if (isProject && lines[line].StartsWith("EndProject"))
                {
                    block.Add(lines[line]);
                    sln.EvaluateProject(block.ToArray());
                    isProject = false;
                }
                // Global Section
                if (!isHeader && lines[line].StartsWith("\tGlobalSection("))
                {
                    block           = new List <string>();
                    isGlobalSection = true;
                }
                if (isGlobalSection && lines[line].StartsWith("\tEndGlobalSection"))
                {
                    block.Add(lines[line]);
                    sln.EvaluateGlobalSection(block.ToArray());
                    isGlobalSection = false;
                }

                block.Add(lines[line]);
                line++;
            }

            return(sln);
        }
        internal static string[] GetGlobalSections(this VsSolutionFile sln)
        {
            sln.RebuildSectionNestedProjects();

            var text = new List <string>();

            text.Add("Global");
            foreach (var item in sln.GlobalSections)
            {
                text.AddRange(item.Value.GetLines());
            }
            text.Add("EndGlobal");

            return(text.ToArray());
        }
        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);
            }
        }
예제 #10
0
        private static void EvaluateProject(this VsSolutionFile sln, string[] block)
        {
            var items         = block[0].Split(',');
            var projectId     = Guid.Parse(items[2].Substring(3, 36));
            var projectTypeId = Guid.Parse(items[0].Substring(10, 36));
            var projectName   = items[0].Substring(53, items[0].Length - 53 - 1);
            var projectPath   = items[1].Trim().Substring(1, items[1].Trim().Length - 2);

            var proj = sln.AddProject(projectTypeId, projectName, projectPath, projectId);

            // Solution-Files
            if (proj.ProjectTypeId == VsSolutionProjectTypeIds.VsSolutionProjectTypeSolutionFolder &&
                block[1].StartsWith("\tProjectSection(SolutionItems)"))
            {
                for (int line = 2; line < block.Length - 2; line++)
                {
                    var values = block[line].Split('=');
                    var name   = values[0].Trim();
                    var path   = values[1].Trim();
                    proj.Files.Add(name, path);
                }
            }
        }
예제 #11
0
 private static void EvaluateHeader(this VsSolutionFile sln, string[] block)
 {
     //VsVersionHeader = block.Concat("\n");
 }
        public static VsSolutionFileProject AddSolutionFolder(this VsSolutionFile sln, string foldername)
        {
            var proj = sln.AddProject(VsSolutionProjectTypeIds.VsSolutionProjectTypeSolutionFolder, foldername, foldername, Guid.NewGuid());

            return(proj);
        }
        public static string Save(this VsSolutionFile sln)
        {
            var filepath = sln.SolutionFolder + @"\" + sln.Filename;

            return(SaveAs(sln, filepath));
        }