Microsoft.VisualStudio.Project.ReferenceNode.AddReference C# (CSharp) Method

AddReference() public method

Links a reference node to the project and hierarchy.
public AddReference ( ) : void
return void
        public virtual void AddReference()
        {
            ReferenceContainerNode referencesFolder = this.ProjectManager.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;
            Debug.Assert(referencesFolder != null, "Could not find the References node");

            CannotAddReferenceErrorMessage referenceErrorMessageHandler = null;

            if(!this.CanAddReference(out referenceErrorMessageHandler))
            {
                if(referenceErrorMessageHandler != null)
                {
                    referenceErrorMessageHandler.DynamicInvoke(new object[] { });
                }
                return;
            }

            // 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;
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Adds a reference to this container using the selector data structure to identify it.
        /// </summary>
        /// <param name="selectorData">data describing selected component</param>
        /// <returns>Reference in case of a valid reference node has been created. Otherwise null</returns>
        public virtual ReferenceNode AddReferenceFromSelectorData(VSCOMPONENTSELECTORDATA selectorData, string wrapperTool = null)
        {
            //Make sure we can edit the project file
            ThreadHelper.ThrowIfNotOnUIThread();

            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            //Create the reference node
            ReferenceNode node = null;

            try
            {
                node = CreateReferenceNode(selectorData, wrapperTool);
            }
            catch (ArgumentException)
            {
                // Some selector data was not valid.
            }


            //Add the reference node to the project if we have a valid reference node
            if (node != null)
            {
                // Does such a reference already exist in the project?
                ReferenceNode existingNode;
                if (node.IsAlreadyAdded(out existingNode))
                {
                    return(existingNode);
                }
                // This call will find if the reference is in the project and, in this case
                // will not add it again, so the parent node will not be set.
                node.AddReference();
                if (null == node.Parent)
                {
                    // The reference was not added, so we can not return this item because it
                    // is not inside the project.
                    return(null);
                }
            }

            return(node);
        }
All Usage Examples Of Microsoft.VisualStudio.Project.ReferenceNode::AddReference