public void SolutionEvents_ProjectRemoved(Project project)
        {
            Trace.WriteLine("Project Removed: " + project.Name);

            StorageProvider storage = new StorageProvider();

            var items = storage.Load(project.DTE.Solution).GetProjectsThatReference(project.UniqueName);

            List<ProjectReferenceToRemove> workToDo = new List<ProjectReferenceToRemove>();

            foreach (var item in items)
            {
                Project projectToAddReferenceTo = null;
                foreach (Project p in project.DTE.Solution.Projects)
                {
                    if (p.UniqueName == item.SourceProject)
                    {
                        projectToAddReferenceTo = p;
                        break;
                    }
                }

                string filePath = item.KnownPaths;

                if (filePath == null)
                    continue;

                if (projectToAddReferenceTo != null)
                {
                    workToDo.Add(new ProjectReferenceToRemove
                        {
                            ProjectNeedingReference = projectToAddReferenceTo,
                            FilePath = filePath,
                            ProjectRemoving = project
                        });
                }
            }

            StringBuilder sb = new StringBuilder();
            foreach (var item in workToDo)
            {
                sb.AppendFormat("{0} will refer back to: {1}\n\n", item.ProjectNeedingReference.Name, ToRelative(item.FilePath, item.ProjectNeedingReference.FullName));
            }

            if (workToDo.Count == 0)
                return;

            if(!AskUserToProceed("Switch Project Reference to File References?",  sb.ToString()))
                return;

            foreach (var item in workToDo)
            {
                AddReference(item.ProjectNeedingReference, item.ProjectRemoving, item.FilePath);
            }
        }
Beispiel #2
0
        private static void SaveChanges(Project projectAdded, IEnumerable <ProjectReferenceToAdd> changes)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
            var storage = new StorageProvider();

            var referenceChanges = storage.Load(projectAdded.DTE.Solution);

            foreach (var item in changes)
            {
                referenceChanges.AddUpdate(item.Project.Project.UniqueName, item.ProjectToReference.UniqueName,
                                           ToRelative(item.Reference.Path, item.Project.Project.FullName));
            }

            storage.Save(projectAdded.DTE.Solution, referenceChanges);
        }
Beispiel #3
0
        public void SolutionEvents_ProjectRemoved(Project project)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
            Trace.WriteLine("Project Removed: " + project.Name);

            StorageProvider storage = new StorageProvider();

            IEnumerable <ProjectReferenceChange> items = storage.Load(project.DTE.Solution)
                                                         .GetProjectsThatReference(project.UniqueName);

            List <ProjectReferenceToRemove> workToDo = new List <ProjectReferenceToRemove>();

            foreach (var item in items)
            {
                Project projectToAddReferenceTo = null;
                foreach (Project p in project.DTE.Solution.Projects)
                {
                    if (p.UniqueName == item.SourceProject)
                    {
                        projectToAddReferenceTo = p;
                        break;
                    }
                }

                string filePath = item.KnownPaths;

                if (filePath == null)
                {
                    continue;
                }

                if (projectToAddReferenceTo != null)
                {
                    workToDo.Add(new ProjectReferenceToRemove
                    {
                        ProjectNeedingReference = projectToAddReferenceTo,
                        FilePath        = filePath,
                        ProjectRemoving = project
                    });
                }
            }

            StringBuilder sb = new StringBuilder();

            foreach (var item in workToDo)
            {
                sb.AppendFormat("Switch {0} to refer back to a file reference: {1}\n\n", item.ProjectNeedingReference.Name, ToRelative(item.FilePath, item.ProjectNeedingReference.FullName));
            }

            if (workToDo.Count == 0)
            {
                return;
            }

            if (!AskUserToProceed("Switch Project Reference to File References?", sb.ToString()))
            {
                return;
            }

            foreach (var item in workToDo)
            {
                AddReference(item.ProjectNeedingReference, item.ProjectRemoving, item.FilePath);
            }
        }
        private static void SaveChanges(Project projectAdded, IEnumerable<ProjectReferenceToAdd> changes)
        {
            var storage = new StorageProvider();

            var referenceChanges = storage.Load(projectAdded.DTE.Solution);

            foreach (var item in changes)
            {
                referenceChanges.AddUpdate(item.Project.Project.UniqueName, item.ProjectToReference.UniqueName,
                                           ToRelative(item.Reference.Path, item.Project.Project.FullName));
            }

            storage.Save(projectAdded.DTE.Solution, referenceChanges);
        }