/// <summary>
        /// Links a reference node to the project and hierarchy.  Returns true if succeeds, false otherwise.
        /// </summary>
        public virtual bool AddReference()
        {
            ReferenceContainerNode referencesFolder = this.ProjectMgr.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;

            Debug.Assert(referencesFolder != null, "Could not find the References node");


            var checkResult = CheckIfCanAddReference();

            if (!checkResult.Ok)
            {
                if (!string.IsNullOrEmpty(checkResult.Message))
                {
                    throw new InvalidOperationException(checkResult.Message);
                }
                return(false);
            }

            // Link the node to the project file.
            this.BindReferenceData();

            // At this point force the item to be refreshed
            this.ItemNode.RefreshProperties();

            referencesFolder.AddChild(this);

            return(true);
        }
        /// <summary>
        /// Checks if a reference is already added. The method parses all references and compares the Url.
        /// </summary>
        /// <returns>true if the assembly has already been added.</returns>
        public virtual bool IsAlreadyAdded(out ReferenceNode existingNode)
        {
            ReferenceContainerNode referencesFolder = this.ProjectMgr.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;

            Debug.Assert(referencesFolder != null, "Could not find the References node");

            for (HierarchyNode n = referencesFolder.FirstChild; n != null; n = n.NextSibling)
            {
                ReferenceNode referenceNode = n as ReferenceNode;
                if (null != referenceNode)
                {
                    if (!string.IsNullOrEmpty(referenceNode.SimpleName) && 0 == string.CompareOrdinal(referenceNode.SimpleName, this.SimpleName))
                    {
                        existingNode = referenceNode;
                        return(true);
                    }
                }
            }

            existingNode = null;
            return(false);
        }
        /// <summary>
        /// Checks if a reference is already added. The method parses all references and compares the the FinalItemSpec and the Guid.
        /// </summary>
        /// <returns>true if the assembly has already been added.</returns>
        public /*protected, but public for FSharp.Project.dll*/ override bool IsAlreadyAdded(out ReferenceNode existingNode)
        {
            ReferenceContainerNode referencesFolder = this.ProjectMgr.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;

            Debug.Assert(referencesFolder != null, "Could not find the References node");

            for (HierarchyNode n = referencesFolder.FirstChild; n != null; n = n.NextSibling)
            {
                if (n is ComReferenceNode)
                {
                    ComReferenceNode referenceNode = n as ComReferenceNode;

                    // We check if the name and guids are the same
                    if (referenceNode.TypeGuid == this.TypeGuid && String.Compare(referenceNode.Caption, this.Caption, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        existingNode = referenceNode;
                        return(true);
                    }
                }
            }

            existingNode = null;
            return(false);
        }