Пример #1
0
        /// <summary>
        /// Recursively search if this project reference guid is in cycle.
        /// </summary>
        private bool IsReferenceInCycle(Guid projectGuid)
        {
            IVsHierarchy hierarchy = VsShellUtilities.GetHierarchy(this.ProjectMgr.Site, projectGuid);

            IReferenceContainerProvider provider = hierarchy as IReferenceContainerProvider;

            if (provider != null)
            {
                IReferenceContainer referenceContainer = provider.GetReferenceContainer();

                Debug.Assert(referenceContainer != null, "Could not found the References virtual node");

                foreach (ReferenceNode refNode in referenceContainer.EnumReferences())
                {
                    ProjectReferenceNode projRefNode = refNode as ProjectReferenceNode;
                    if (projRefNode != null)
                    {
                        if (projRefNode.ReferencedProjectGuid == this.ProjectMgr.ProjectIDGuid)
                        {
                            return(true);
                        }

                        if (this.IsReferenceInCycle(projRefNode.ReferencedProjectGuid))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// Recursively search if this project reference guid is in cycle.
        /// </summary>
        private bool IsReferenceInCycle(Guid projectGuid)
        {
            // TODO: This has got to be wrong, it doesn't work w/ other project types.
            IVsHierarchy hierarchy = VsShellUtilities.GetHierarchy(this.ProjectMgr.Site, projectGuid);

            IReferenceContainerProvider provider = hierarchy.GetProject().GetCommonProject() as IReferenceContainerProvider;

            if (provider != null)
            {
                IReferenceContainer referenceContainer = provider.GetReferenceContainer();

                Utilities.CheckNotNull(referenceContainer, "Could not found the References virtual node");

                foreach (ReferenceNode refNode in referenceContainer.EnumReferences())
                {
                    ProjectReferenceNode projRefNode = refNode as ProjectReferenceNode;
                    if (projRefNode != null)
                    {
                        if (projRefNode.ReferencedProjectGuid == this.ProjectMgr.ProjectIDGuid)
                        {
                            return(true);
                        }

                        if (this.IsReferenceInCycle(projRefNode.ReferencedProjectGuid))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        private List <ProjectReferenceNode> GetProjectReferencesContainingThisProject(IVsHierarchy inputHierarchy)
        {
            List <ProjectReferenceNode> projectReferences = new List <ProjectReferenceNode>();

            if (this.Solution == null || inputHierarchy == null)
            {
                return(projectReferences);
            }

            uint             flags            = (uint)(__VSENUMPROJFLAGS.EPF_ALLPROJECTS | __VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION);
            Guid             enumOnlyThisType = Guid.Empty;
            IEnumHierarchies enumHierarchies  = null;

            ThreadHelper.ThrowIfNotOnUIThread();

            ErrorHandler.ThrowOnFailure(this.Solution.GetProjectEnum(flags, ref enumOnlyThisType, out enumHierarchies));
            Debug.Assert(enumHierarchies != null, "Could not get list of hierarchies in solution");

            IVsHierarchy[] hierarchies = new IVsHierarchy[1];
            uint           fetched;
            int            returnValue = VSConstants.S_OK;

            do
            {
                returnValue = enumHierarchies.Next(1, hierarchies, out fetched);
                Debug.Assert(fetched <= 1, "We asked one project to be fetched VSCore gave more than one. We cannot handle that");
                if (returnValue == VSConstants.S_OK && fetched == 1)
                {
                    IVsHierarchy hierarchy = hierarchies[0];
                    Debug.Assert(hierarchy != null, "Could not retrieve a hierarchy");
                    IReferenceContainerProvider provider = hierarchy as IReferenceContainerProvider;
                    if (provider != null)
                    {
                        IReferenceContainer referenceContainer = provider.GetReferenceContainer();

                        Debug.Assert(referenceContainer != null, "Could not found the References virtual node");
                        ProjectReferenceNode projectReferenceNode = GetProjectReferenceOnNodeForHierarchy(referenceContainer.EnumReferences(), inputHierarchy);
                        if (projectReferenceNode != null)
                        {
                            projectReferences.Add(projectReferenceNode);
                        }
                    }
                }
            } while(returnValue == VSConstants.S_OK && fetched == 1);

            return(projectReferences);
        }