示例#1
0
        private TreeNode CreateProjectNode(TreeNode root, SolutionProject project)
        {
            if (this.projectNodes.ContainsKey(project))
            {
                return(projectNodes[project]);
            }

            var parent = root;

            if (project.ParentProject != null)
            {
                parent = CreateProjectNode(root, project.ParentProject);
            }

            var node = new TreeNode(project.Name);

            node.Tag = project;
            var projectType = project.IsFolder ? ProjectType.SolutionFolder : ProjectTypes.Find(project.ProjectTypeId);

            node.ImageKey         = ProjectIcons[projectType];
            node.SelectedImageKey = node.ImageKey;
            parent.Nodes.Add(node);
            this.projectNodes.Add(project, node);
            return(node);
        }
示例#2
0
        public bool IsProjectFile(SolutionFileVersion solutionFileVersion)
        {
            if (string.IsNullOrEmpty(Path.GetExtension(_fullPath)))
            {
                return(false);
            }

            string fileExtension = Path.GetExtension(_fullPath).ToLower().Substring(1); // Remove leading "."
            var    projectType   = ProjectTypes.Find(fileExtension);

            if (projectType != null && (solutionFileVersion & projectType.SupportedVersions) != 0)
            {
                return(GetProjectId() != Guid.Empty);
            }
            else
            {
                return(false);
            }
        }
        private void ProcessProjectFile(string projectPath, IList <SolutionProject> projects,
                                        IEnumerable <string> includeFilter, IEnumerable <string> excludeFilter, ProjectAnalyzer projectAnalyzer, bool allowDuplicates)
        {
            ++this.NumberOfProjectsFound;
            string message = string.Format("Found project {0}", Path.GetFileNameWithoutExtension(projectPath));

            bool skip = false;

            if (includeFilter.Any() && !ProjectHasMatch(projectPath, includeFilter))
            {
                skip = true;
            }
            if (excludeFilter.Any() && ProjectHasMatch(projectPath, excludeFilter))
            {
                skip = true;
            }

            if (skip)
            {
                ++this.NumberOfProjectsSkipped;
                message += " (skipped)";
            }
            else
            {
                var project = new SolutionProject();
                project.ProjectTypeId = ProjectTypes.Find(Path.GetExtension(projectPath).Substring(1)).ProjectGuid;
                project.ProjectId     = projectAnalyzer.GetProjectId();
                project.Name          = Path.GetFileNameWithoutExtension(projectPath);
                project.Path          = Utils.GetRelativePath(this._options.SolutionFolderPath, projectPath);

                if (!allowDuplicates && projects.Any(x => x.Name == project.Name))
                {
                    throw new InvalidOperationException(string.Format("Duplicate project: {0}. All projects should have unique names across the solution.", project.Name));
                }

                projects.Add(project);
            }

            this._logger.Write(message);
        }
示例#4
0
        public Solution Build(Solution oldSolution, IList <SolutionProject> projects)
        {
            this.NumberOfProjectsAdded   = 0;
            this.NumberOfProjectsRemoved = 0;

            var addProject = new Action <Solution, SolutionProject>((s, p) =>
            {
                s.Projects.Add(p);
                ++this.NumberOfProjectsAdded;
                _logger.Write(string.Format("Added project {0}", p.Name));
            });

            var removeProject = new Action <Solution, SolutionProject>((s, p) =>
            {
                s.Projects.Remove(p);
                _logger.Write(string.Format("Removed project {0}", p.Name));
                ++this.NumberOfProjectsRemoved;
            });

            Solution newSolution;

            if (oldSolution == null || _options.UpdateMode == SolutionUpdateMode.Replace)
            {
                newSolution             = new Solution();
                newSolution.FileVersion = _options.SolutionFileVersion;

                foreach (var project in projects)
                {
                    addProject(newSolution, project);
                }
            }
            else
            {
                newSolution = oldSolution.Clone() as Solution;

                foreach (var project in projects)
                {
                    if (!newSolution.Projects.Contains(project))
                    {
                        addProject(newSolution, project);
                    }
                }

                if (_options.UpdateMode == SolutionUpdateMode.AddRemove)
                {
                    var projectsToRemove = new List <SolutionProject>();
                    foreach (var project in newSolution.Projects)
                    {
                        if (ProjectTypes.Find(project.ProjectTypeId) != null && !projects.Contains(project))
                        {
                            projectsToRemove.Add(project);
                        }
                    }

                    foreach (var project in projectsToRemove)
                    {
                        removeProject(newSolution, project);
                    }
                }
            }

            if (_options.SolutionFolderLevels != 0)
            {
                MergeSolutionFolders(newSolution);
            }

            return(newSolution);
        }
示例#5
0
        private ProjectType GetProjectType(string path)
        {
            string projectFileExtension = Path.GetExtension(path).Substring(1).ToLower();

            return(ProjectTypes.Find(projectFileExtension));
        }