GetSolutionFolderPath() public method

public GetSolutionFolderPath ( SolutionProject project ) : string
project SolutionProject
return string
Esempio n. 1
0
        private void MergeSolutionFolders(Solution solution)
        {
            var solutionFolders = GenerateSolutionFolders(solution);
            foreach (var project in solution.Projects)
            {
                if (project.IsFolder)
                {
                    string solutionFolderPath = solution.GetSolutionFolderPath(project);
                    if (solutionFolders.Contains(solutionFolderPath))
                    {
                        solutionFolders.Remove(solutionFolderPath);
                    }
                }
            }

            // Add new solution folders that are not present in current solution
            var solutionFolderMap = new Dictionary<string, Guid>();
            foreach (var solutionFolder in solutionFolders)
            {
                SolutionProject parentProject = null;
                int index = solutionFolder.LastIndexOf('.');
                if (index > 0)
                {
                    parentProject = solution.FindFolderWithPath(solutionFolder.Substring(0, index));
                }

                var project = new SolutionProject()
                {
                    ProjectTypeId = ProjectType.SolutionFolder.ProjectGuid,
                    ProjectId = Guid.NewGuid(),
                    ParentProject = parentProject,
                    Name = solution.GetSolutionFolderName(solutionFolder),
                    Path = solution.GetSolutionFolderName(solutionFolder),
                };

                solution.Projects.Add(project);
                solutionFolderMap.Add(solutionFolder, project.ProjectId);
            }

            // Now attach parents to projects
            foreach (var project in solution.Projects)
            {
                string folderPath = EvaluateProjectFolderPath(solution, project, _options.SolutionFolderLevels);
                if (folderPath != null)
                {
                    SolutionProject parentProject = solution.FindFolderWithPath(folderPath);
                    if (parentProject != null)
                    {
                        project.ParentProject = parentProject;
                    }
                }
            }
        }
Esempio n. 2
0
        internal string EvaluateProjectFolderPath(Solution solution, SolutionProject project, int folderLevels = -1)
        {
            if (folderLevels < 0)
                folderLevels = _options.SolutionFolderLevels;

            if (project.IsFolder)
            {
                string solutionFolderPath = solution.GetSolutionFolderPath(project);
                return solutionFolderPath.Contains(".") ? solutionFolderPath.Substring(0, solutionFolderPath.LastIndexOf('.')) : null;
            }
            else
            {
                string folderBaseName = SkipCommonLevels(EvaluateFolderBaseName(project));
                int subnameCount = 0;
                int index = 0;
                while (subnameCount < folderLevels && index >= 0)
                {
                    subnameCount++;
                    index = folderBaseName.IndexOf('.', index + 1);
                }
                if (index < 0)
                {
                    index = folderBaseName.Length;
                }
                return folderBaseName.Substring(0, index);
            }
        }