Beispiel #1
0
        private static IEnumerable <ProjectReferenceToAdd> FindChanges(Project projectAdded)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
            string assemblyName = projectAdded.GetAssemblyName();

            var solution = projectAdded.DTE.Solution;

            Microsoft.Build.Evaluation.Project buildProjAdded =
                ProjectCollection.GlobalProjectCollection.GetLoadedProjects(projectAdded.FullName).First();

            var changes = new List <ProjectReferenceToAdd>();

            foreach (Project project in solution.Projects)
            {
                if (project.UniqueName == projectAdded.UniqueName)
                {
                    continue;
                }

                VSProject vsProject = project.Object as VSProject;

                if (vsProject == null)
                {
                    continue;
                }

                foreach (Reference reference in vsProject.References)
                {
                    //If this project already has a project reference to the project being added then we don't need to do anything.
                    if (reference.SourceProject != null && projectAdded == reference.SourceProject)
                    {
                        break;
                    }

                    if (Path.GetFileNameWithoutExtension(reference.Path).Equals(assemblyName))
                    {
                        changes.Add(new ProjectReferenceToAdd
                        {
                            Reference          = reference,
                            Project            = vsProject,
                            ProjectToReference = projectAdded
                        }
                                    );
                    }
                }
            }
            return(changes);
        }
        private static IEnumerable<ProjectReferenceToAdd> FindChanges(Project projectAdded)
        {
            string assemblyName = projectAdded.GetAssemblyName();

            var solution = projectAdded.DTE.Solution;

            Microsoft.Build.Evaluation.Project buildProjAdded =
                   ProjectCollection.GlobalProjectCollection.GetLoadedProjects(projectAdded.FullName).First();

            var changes = new List<ProjectReferenceToAdd>();

            foreach (Project project in solution.Projects)
            {
                if (project.UniqueName == projectAdded.UniqueName)
                    continue;

                VSProject vsProject = project.Object as VSProject;

                if (vsProject == null) continue;

                foreach (Reference reference in vsProject.References)
                {
                    if (Path.GetFileNameWithoutExtension(reference.Path).Equals(assemblyName))
                    {
                        changes.Add(new ProjectReferenceToAdd
                        {
                            Reference = reference,
                            Project = vsProject,
                            ProjectToReference = projectAdded
                        }
                            );
                    }
                }
            }
            return changes;
        }