public void AddProject(Project project)
 {
     _items.Add(new SolutionProject(this) {
         Guid = project.Guid,
         Name = project.Name,
         Filepath = project.Filepath
     });
 }
Exemple #2
0
        public void CanReadProjectFileWithoutProjectReferences()
        {
            CopyTestDataToPath("CsTestProject1.csproj", _testDataPath);

            var project = new Project(Path.Combine(_testDataPath, "CsTestProject1.csproj"));
            project.Load();

            Assert.AreEqual("CsTestProject1", project.Name);
            Assert.AreEqual("CsTestProject1", project.AssemblyName);
            Assert.IsEmpty(project.ProjectReferences);
        }
Exemple #3
0
        public void CanReadProjectFileWithProjectReferences()
        {
            CopyTestDataToPath("CsTestProject2.csproj", Path.Combine(_testDataPath, "p2"));

            var project = new Project(Path.Combine(_testDataPath, "p2", "CsTestProject2.csproj"));
            project.Load();

            Assert.AreEqual("CsTestProject2", project.Name);
            Assert.AreEqual("CsTestProject2", project.AssemblyName);
            Assert.AreEqual(1, project.ProjectReferences.Count);
            Assert.AreEqual(1, project.ProjectReferences.Count);
            Assert.AreEqual(Path.Combine(_testDataPath, "p1", "CsTestProject1.csproj"), project.ProjectReferences[0]);
        }
 private ProjectViewModel CreateProjectViewModel(Project project, DirectoryViewModel parent)
 {
     return new ProjectViewModel(parent, project);
 }
 public SolutionProject(Project project, SolutionFolder parent)
     : base(parent)
 {
     _project = project;
 }
        private SolutionFolder GetSolutionFolder(Project project)
        {
            // get chain of folders from root to project
            var folderNames = new List<string>();
            var projectFolder = project.Parent;
            while (projectFolder.Parent != null) {
                folderNames.Add(projectFolder.Name);
                projectFolder = projectFolder.Parent;
            }
            folderNames.Reverse();

            var folder = GetOrCreateReferenceFolder();
            foreach (var folderName in folderNames) {
                folder = folder.GetOrCreateSubfolder(folderName);
            }
            return folder;
        }
        private void AddReferencedProjects(Project project, int depth)
        {
            foreach (var projectReference in project.ProjectReferences) {
                Project referencedProject;
                if (!_projects.TryGetValue(projectReference, out referencedProject)) {
                    // TODO Present to user?
                    _log.Warn("Project {0} references unknown project {1}", project.Name, projectReference);
                    continue;
                }

                if (_solutionRoot.ContainsProject(referencedProject)) {
                    continue;
                }

                var folder = GetSolutionFolder(referencedProject);
                if (!folder.ContainsProject(referencedProject)) {
                    folder.AddProject(referencedProject);

                    if (depth > 1) {
                        AddReferencedProjects(referencedProject, depth - 1);
                    }
                }
            }
        }
        private static bool RemoveProject(SolutionFolder solutionFolder, Project project)
        {
            bool removed = false;
            var item = solutionFolder.Items.SingleOrDefault(p => p.Guid == project.Guid);
            if (item != null) {
                solutionFolder.Items.Remove(item);
                removed = true;
            }

            var foldersToRemove = new List<SolutionFolder>();
            foreach (var subfolder in solutionFolder.Items.OfType<SolutionFolder>()) {
                if (RemoveProject(subfolder, project)) {
                    removed = true;
                    if (subfolder.Items.Count == 0) {
                        foldersToRemove.Add(subfolder);
                    }
                }
            }
            if (foldersToRemove.Count > 0) {
                foreach (var folder in foldersToRemove) {
                    solutionFolder.Items.Remove(folder);
                }
            }
            return removed;
        }
        public void AddProject(Project project)
        {
            IsSccBound |= project.IsSccBound;

            if (_solutionRoot.ContainsProject(project)) {
                return;
            }

            _solutionRoot.AddProject(project);

            var referenceFolder = _solutionRoot.Items.OfType<SolutionFolder>().SingleOrDefault();
            if (referenceFolder != null) {
                RemoveProject(referenceFolder, project);
            }

            if (_settings.IncludeReferencedProjects) {
                AddReferencedProjects(project, _settings.ReferenceTreeDepth);
            }

            Refresh();
        }
 public ProjectViewModel(DirectoryViewModel parent, Project project)
     : base(parent)
 {
     _project = project;
 }
        public void AddProject(Project project)
        {
            IsSccBound |= project.IsSccBound;

            if (_solutionRoot.ContainsProject(project)) {
                return;
            }

            _solutionRoot.AddProject(project);

            var referenceFolder = _solutionRoot.Items.OfType<SolutionFolder>().SingleOrDefault();
            if (referenceFolder != null) {
                RemoveProject(referenceFolder, project);
            }

            if (_settings.IncludeReferencedProjects) {
                AddReferencedProjects(project, _settings.ReferenceTreeDepth);
            }

            var projectCount = SolutionItems.Flatten<SolutionItem, SolutionProject, SolutionFolder>(p => p.Items).Count();
            _statusMessenger.Show(String.Format("{0} projects in the solution.", projectCount));

            Refresh();
        }
 public bool ContainsProject(Project project)
 {
     return _items.OfType<SolutionProject>().Any(p => p.Guid == project.Guid);
 }