상속: ReferenceNode
        private static ProjectReferenceNode GetProjectReferenceOnNodeForHierarchy(IList <ReferenceNode> references, IVsHierarchy inputHierarchy)
        {
            if (references == null)
            {
                return(null);
            }

            Guid projectGuid;

            ErrorHandler.ThrowOnFailure(inputHierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid));

            string canonicalName;

            ErrorHandler.ThrowOnFailure(inputHierarchy.GetCanonicalName(VSConstants.VSITEMID_ROOT, out canonicalName));
            foreach (ReferenceNode refNode in references)
            {
                ProjectReferenceNode projRefNode = refNode as ProjectReferenceNode;
                if (projRefNode != null)
                {
                    if (projRefNode.ReferencedProjectGuid == projectGuid)
                    {
                        return(projRefNode);
                    }

                    // Try with canonical names, if the project that is removed is an unloaded project than the above criteria will not pass.
                    if (!String.IsNullOrEmpty(projRefNode.Url) && NativeMethods.IsSamePath(projRefNode.Url, canonicalName))
                    {
                        return(projRefNode);
                    }
                }
            }

            return(null);
        }
예제 #2
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);
        }
        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);
        }
        private static ProjectReferenceNode GetProjectReferenceOnNodeForHierarchy(IList <ReferenceNode> references, IVsHierarchy inputHierarchy)
        {
            if (references == null)
            {
                return(null);
            }

            Guid projectGuid;

            // !EFW - This is an odd one.  Open a file not contained within a project in the active solution and
            // then close it.  When you do, this method is called and it fails here.  The file is hosted in the
            // Miscellaneous Files hierarchy.  In such cases, we'll just ignore it and return null.
            if (inputHierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT,
                                               (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid) != VSConstants.S_OK)
            {
                return(null);
            }

            string canonicalName;

            ErrorHandler.ThrowOnFailure(inputHierarchy.GetCanonicalName(VSConstants.VSITEMID_ROOT, out canonicalName));

            foreach (ReferenceNode refNode in references)
            {
                ProjectReferenceNode projRefNode = refNode as ProjectReferenceNode;

                if (projRefNode != null)
                {
                    if (projRefNode.ReferencedProjectGuid == projectGuid)
                    {
                        return(projRefNode);
                    }

                    // Try with canonical names, if the project that is removed is an unloaded project that the
                    // above criteria will not pass.
                    if (!String.IsNullOrEmpty(projRefNode.Url) && NativeMethods.IsSamePath(projRefNode.Url, canonicalName))
                    {
                        return(projRefNode);
                    }
                }
            }

            return(null);
        }
예제 #5
0
 public ProjectReferencesProperties(ProjectReferenceNode node)
     : base(node)
 {
 }
 public ProjectReferencesProperties(ProjectReferenceNode node)
     : base(node)
 {
 }