예제 #1
0
        public EnvDTE.Project CreateSolutionFolder(string relativePath, EnvDTE.Project parentFolder)
        {
            if (string.IsNullOrEmpty(relativePath)) return null;

            var arr = relativePath.Split(new char[] {'\\'}, StringSplitOptions.RemoveEmptyEntries);
            if (parentFolder == null)
            {
                var folders = CurrentSolution.GetFolders();
                var selected = folders.FirstOrDefault(x => x.Name.ToLower() == arr.First().ToLower());
                if (selected == null)
                    selected = (CurrentSolution as EnvDTE80.Solution2).AddSolutionFolder(arr.First());

                if (arr.Length == 1)
                    return selected;
                else
                    return CreateSolutionFolder(string.Join(@"\", arr.Skip(1).Take(arr.Length - 1)), selected);
            }
            else
            {
                var folders = parentFolder.GetFolders();
                var selected = folders.FirstOrDefault(x => x.Name.ToLower() == arr.First().ToLower());
                if (selected == null)
                    selected = (parentFolder.Object as EnvDTE80.SolutionFolder).AddSolutionFolder(arr.First());

                if (arr.Length == 1)
                    return selected;
                else
                    return CreateSolutionFolder(string.Join(@"\", arr.Skip(1).Take(arr.Length - 1)), selected);
            }
        }