예제 #1
0
        private EnvDTE.ProjectItems GetOrCreateFolderItem(EnvDTE.ProjectItems parentItems, string folderPath) {
            var relativeFolderParts = folderPath.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string relativefolderPart in relativeFolderParts) {
                var folderItem = FindItemByName(parentItems, relativefolderPart);
                if (folderItem == null) {
                    folderItem = parentItems.AddFolder(relativefolderPart);
                }
                parentItems = folderItem.ProjectItems;
            }

            return parentItems;
        }
        private static void BuildStructure(EnvDTE.ProjectItems projectItems, string[] levels, int currentLevel)
        {
            if (currentLevel == levels.Length)
                return;

            var folderName = levels[currentLevel];
            var toBeCreated = true;
            EnvDTE.ProjectItem newProjectItem = null;
            foreach (EnvDTE.ProjectItem pi in projectItems)
            {
                if (pi.Name == folderName && pi.Kind == KIND_FOLDER)
                {
                    newProjectItem = pi;
                    toBeCreated = false;
                    break;
                }
            }
            if (toBeCreated)
            {
                newProjectItem = projectItems.AddFolder(folderName, KIND_FOLDER);
            }
            BuildStructure(newProjectItem.ProjectItems, levels, currentLevel + 1);
        }