Пример #1
0
        /// <summary>
        /// This function ensures that some properies of the reference are set.
        /// </summary>
        private void SetReferenceProperties()
        {
            UIThread.MustBeCalledFromUIThread();

            // Set a default HintPath for msbuild to be able to resolve the reference.
            this.ItemNode.SetMetadata(ProjectFileConstants.HintPath, this.assemblyPath);

            // Resolve assembly referernces. This is needed to make sure that properties like the full path
            // to the assembly or the hint path are set.
            if (!ProjectMgr.BuildProject.Targets.ContainsKey(MsBuildTarget.ResolveAssemblyReferences))
            {
                return;
            }

            if (this.ProjectMgr.Build(MsBuildTarget.ResolveAssemblyReferences) != MSBuildResult.Successful)
            {
                return;
            }

            // Check if we have to resolve again the path to the assembly.
            if (string.IsNullOrEmpty(this.assemblyPath))
            {
                ResolveReference();
            }

            // Make sure that the hint path if set (if needed).
            SetHintPathAndPrivateValue();
        }
Пример #2
0
        /// <summary>
        /// Links a reference node to the project and hierarchy.
        /// </summary>
        public virtual void AddReference()
        {
            UIThread.MustBeCalledFromUIThread();

            ReferenceContainerNode referencesFolder = this.ProjectMgr.GetReferenceContainer() as ReferenceContainerNode;

            Utilities.CheckNotNull(referencesFolder, "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;
        }
Пример #3
0
        public HierarchyNode this[uint itemId] {
            get {
                UIThread.MustBeCalledFromUIThread();

                int i = (int)itemId - 1;
                if (0 <= i && i < _ids.Count)
                {
                    return(_ids[i]);
                }
                return(null);
            }
        }
Пример #4
0
        public void Remove(HierarchyNode node)
        {
            UIThread.MustBeCalledFromUIThread();

            int i = (int)node.ID - 1;

            if (i < 0 ||
                i >= _ids.Count ||
                !object.ReferenceEquals(node, _ids[i]))
            {
                throw new InvalidOperationException("Removing node with invalid ID or map is corrupted");
            }

            _ids[i] = null;
            _freedIds.Push(i);
        }
Пример #5
0
        /// <summary>
        /// Adds references to this container from a MSBuild project.
        /// </summary>
        public void LoadReferencesFromBuildProject(MSBuild.Project buildProject)
        {
            UIThread.MustBeCalledFromUIThread();

            foreach (string referenceType in SupportedReferenceTypes)
            {
                IEnumerable <MSBuild.ProjectItem> referencesGroup = this.ProjectMgr.BuildProject.GetItems(referenceType);

                bool isAssemblyReference = referenceType == ProjectFileConstants.Reference;
                // If the project was loaded for browsing we should still create the nodes but as not resolved.
                if (isAssemblyReference &&
                    (!ProjectMgr.BuildProject.Targets.ContainsKey(MsBuildTarget.ResolveAssemblyReferences) || this.ProjectMgr.Build(MsBuildTarget.ResolveAssemblyReferences) != MSBuildResult.Successful))
                {
                    continue;
                }

                foreach (MSBuild.ProjectItem item in referencesGroup)
                {
                    ProjectElement element = new MsBuildProjectElement(this.ProjectMgr, item);

                    ReferenceNode node = CreateReferenceNode(referenceType, element);

                    if (node != null)
                    {
                        // Make sure that we do not want to add the item twice to the ui hierarchy
                        // We are using here the UI representation of the Node namely the Caption to find that out, in order to
                        // avoid different representation problems.
                        // Example :<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                        //		  <Reference Include="EnvDTE80" />
                        bool found = false;
                        for (HierarchyNode n = this.FirstChild; n != null && !found; n = n.NextSibling)
                        {
                            if (String.Compare(n.Caption, node.Caption, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                found = true;
                            }
                        }

                        if (!found)
                        {
                            this.AddChild(node);
                        }
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Constructor.  Inititialize member data.
        /// </summary>
        public IDEBuildLogger(IVsOutputWindowPane output, TaskProvider taskProvider, IVsHierarchy hierarchy)
        {
            UIThread.MustBeCalledFromUIThread();
            Utilities.ArgumentNotNull("taskProvider", taskProvider);
            Utilities.ArgumentNotNull("hierarchy", hierarchy);

            Trace.WriteLineIf(Thread.CurrentThread.GetApartmentState() != ApartmentState.STA, "WARNING: IDEBuildLogger constructor running on the wrong thread.");

            IOleServiceProvider site;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hierarchy.GetSite(out site));

            this.taskProvider     = taskProvider;
            this.outputWindowPane = output;
            this.hierarchy        = hierarchy;
            this.serviceProvider  = new ServiceProvider(site);
            this.dispatcher       = Dispatcher.CurrentDispatcher;
        }
Пример #7
0
        /// <summary>
        /// Handles the exclude from project command.
        /// </summary>
        /// <returns></returns>
        internal override int ExcludeFromProject()
        {
            UIThread.MustBeCalledFromUIThread();

            Debug.Assert(this.ProjectMgr != null, "The project item " + this.ToString() + " has not been initialised correctly. It has a null ProjectMgr");
            if (!ProjectMgr.QueryEditProjectFile(false) ||
                !ProjectMgr.QueryFolderRemove(Parent, Url))
            {
                return(VSConstants.E_FAIL);
            }

            for (var child = FirstChild; child != null; child = child.NextSibling)
            {
                // we automatically exclude all children below us too
                int hr = child.ExcludeFromProject();
                if (ErrorHandler.Failed(hr))
                {
                    return(hr);
                }
            }

            ResetNodeProperties();
            ItemNode.RemoveFromProjectFile();
            if (!Directory.Exists(CommonUtils.TrimEndSeparator(Url)))
            {
                ProjectMgr.OnItemDeleted(this);
                Parent.RemoveChild(this);
            }
            else
            {
                ItemNode = new AllFilesProjectElement(Url, ItemNode.ItemTypeName, ProjectMgr);
                if (!ProjectMgr.IsShowingAllFiles)
                {
                    IsVisible = false;
                    ProjectMgr.OnInvalidateItems(Parent);
                }
                ProjectMgr.ReDrawNode(this, UIHierarchyElement.Icon);
                ProjectMgr.OnPropertyChanged(this, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, 0);
            }
            ((IVsUIShell)GetService(typeof(SVsUIShell))).RefreshPropertyBrowser(0);

            return(VSConstants.S_OK);
        }
Пример #8
0
        /// <summary>
        /// Links a reference node to the project and hierarchy.
        /// </summary>
        protected override void BindReferenceData()
        {
            UIThread.MustBeCalledFromUIThread();

            Debug.Assert(this.assemblyName != null, "The AssemblyName field has not been initialized");

            // If the item has not been set correctly like in case of a new reference added it now.
            // The constructor for the AssemblyReference node will create a default project item. In that case the Item is null.
            // We need to specify here the correct project element.
            if (this.ItemNode == null || this.ItemNode is VirtualProjectElement)
            {
                this.ItemNode = new MsBuildProjectElement(this.ProjectMgr, this.assemblyName.FullName, ProjectFileConstants.Reference);
            }

            // Set the basic information we know about
            this.ItemNode.SetMetadata(ProjectFileConstants.Name, this.assemblyName.Name);
            this.ItemNode.SetMetadata(ProjectFileConstants.AssemblyName, Path.GetFileName(this.assemblyPath));

            this.SetReferenceProperties();
        }
Пример #9
0
        public uint Add(HierarchyNode node)
        {
            UIThread.MustBeCalledFromUIThread();

#if DEBUG
            foreach (var item in _ids)
            {
                Debug.Assert(node != item);
            }
#endif
            if (_freedIds.Count > 0)
            {
                var i = _freedIds.Pop();
                _ids[i] = node;
                return((uint)i + 1);
            }
            else
            {
                _ids.Add(node);
                // ids are 1 based
                return((uint)_ids.Count);
            }
        }