コード例 #1
0
        public void TestRenameOfNestedProject()
        {
            UIThreadInvoker.Invoke((ThreadInvoker) delegate()
            {
                //Get the global service provider and the dte
                IServiceProvider sp = VsIdeTestHostContext.ServiceProvider;
                DTE dte             = (DTE)sp.GetService(typeof(DTE));

                string destination  = Path.Combine(TestContext.TestDir, TestContext.TestName);
                ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                IVsHierarchy nestedProjectHierarchy = Utilities.GetNestedHierarchy(project, "ANestedProject");

                if (nestedProjectHierarchy == null)
                {
                    throw new InvalidOperationException("The nested project has not been loaded corectly");
                }

                // Get the id
                NestedProjectNode nestedProjectNode = Utilities.GetNodesOfType <NestedProjectNode>(project)[0];

                project.SetProperty(nestedProjectNode.ID, (int)__VSHPROPID.VSHPROPID_EditLabel, "NewProject");

                this.VerifyNestedProjectRename(project, nestedProjectNode, nestedProjectHierarchy, "NewProject");

                // Now do an indirect rename through the property window.
                object extensibility;
                ErrorHandler.ThrowOnFailure(nestedProjectHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out extensibility));
                EnvDTE.Project nestedAutomationProject = extensibility as EnvDTE.Project;

                EnvDTE.Property fileNameProperty = nestedAutomationProject.Properties.Item("FileName");
                fileNameProperty.Value           = "Project";
                this.VerifyNestedProjectRename(project, nestedProjectNode, nestedProjectHierarchy, "Project");
            });
        }
コード例 #2
0
        public virtual EnvDTE.Project AddFromFile(string fileName)
        {
            ProjectContainerNode projectContainer = (ProjectContainerNode)this.node.ProjectMgr;
            ProjectElement       newElement       = new ProjectElement(projectContainer, fileName, ProjectFileConstants.SubProject);
            NestedProjectNode    newNode          = projectContainer.AddExistingNestedProject(newElement, __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_OPENFILE);

            if (newNode == null)
            {
                return(null);
            }
            // Now that the sub project was created, get its extensibility object so we can return it
            object newProject = null;

            return(ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                if (ErrorHandler.Succeeded(newNode.NestedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out newProject)))
                {
                    return newProject as EnvDTE.Project;
                }
                else
                {
                    return null;
                }
            }));
        }
コード例 #3
0
        public void ProjectGuidTest()
        {
            NestedProjectNode target = projectNode;

            Guid val = new Guid(GuidStrings.GuidNestedProjectFactory);

            Assert.AreEqual(val, target.ProjectGuid, "NestedProjectNode.ProjectGuid was not set correctly.");
        }
コード例 #4
0
        public void ProjectTypeTest()
        {
            NestedProjectNode target = new NestedProjectNode();

            string val = typeof(NestedProjectNode).Name;

            Assert.AreEqual(val, target.ProjectType, "Microsoft.VisualStudio.Project.Samples.NestedProject.NestedProjectNode.ProjectType was not " +
                            "set correctly.");
        }
コード例 #5
0
        public void GetAutomationObjectTest()
        {
            NestedProjectNode target = projectNode;

            object actual = target.GetAutomationObject();

            Assert.IsNotNull(actual, "Failed to initialize an AutomationObject for "
                             + "NestedProjectNode within GetAutomationObject method");
        }
コード例 #6
0
        public void GetConfigurationIndependentPropertyPagesTest()
        {
            NestedProjectNode target = new NestedProjectNode();
            VisualStudio_Project_Samples_NestedProjectNodeAccessor accessor =
                new VisualStudio_Project_Samples_NestedProjectNodeAccessor(target);


            Guid[] actual;
            actual = accessor.GetConfigurationIndependentPropertyPages();

            Assert.IsTrue(actual != null && actual.Length > 0, "The result of GetConfigurationIndependentPropertyPages was unexpected.");
            Assert.IsTrue(actual[0].Equals(typeof(GeneralPropertyPage).GUID), "The value of collection returned by GetConfigurationIndependentPropertyPages is unexpected.");
        }
コード例 #7
0
        public void GetConfigurationDependentPropertyPagesTest()
        {
            NestedProjectNode target = projectNode;
            VisualStudio_Project_Samples_NestedProjectNodeAccessor accessor =
                new VisualStudio_Project_Samples_NestedProjectNodeAccessor(target);

            Guid[] expected = new Guid[] { new Guid("C43AD3DC-7468-48e1-B4D2-AAC0C74A0109") };
            Guid[] actual;

            actual = accessor.GetConfigurationDependentPropertyPages();

            CollectionAssert.AreEqual(expected, actual, "Microsoft.VisualStudio.Project.Samples.NestedProject.NestedProjectNode.GetConfigurationDepe" +
                                      "ndentPropertyPages did not return the expected value.");
        }
コード例 #8
0
        public void GetFormatListTest()
        {
            NestedProjectNode target = new NestedProjectNode();

            string ppszFormatList;

            int expected = VSConstants.S_OK;
            int actual;

            actual = target.GetFormatList(out ppszFormatList);

            Assert.IsFalse(String.IsNullOrEmpty(ppszFormatList), "[out] ppszFormatList in GetFormatList() method was not set correctly.");
            Assert.AreEqual(expected, actual, "Microsoft.VisualStudio.Project.Samples.NestedProject.NestedProjectNode.GetFormatList did no" +
                            "t return the expected value.");
        }
コード例 #9
0
        public virtual EnvDTE.Project AddFromTemplate(string fileName, string destination, string projectName)
        {
            bool isVSTemplate = Utilities.IsTemplateFile(fileName);

            NestedProjectNode newNode = null;

            ThreadHelper.ThrowIfNotOnUIThread();

            if (isVSTemplate)
            {
                // Get the wizard to run, we will get called again and use the alternate code path
                ProjectElement newElement = new ProjectElement(this.node.ProjectMgr, System.IO.Path.Combine(destination, projectName), ProjectFileConstants.SubProject);
                newElement.SetMetadata(ProjectFileConstants.Template, fileName);
                ((ProjectContainerNode)this.node.ProjectMgr).RunVsTemplateWizard(newElement, false);
            }
            else
            {
                if ((String.IsNullOrEmpty(System.IO.Path.GetExtension(projectName))))
                {
                    string targetExtension = System.IO.Path.GetExtension(fileName);
                    projectName = System.IO.Path.ChangeExtension(projectName, targetExtension);
                }

                ProjectContainerNode projectContainer = (ProjectContainerNode)this.node.ProjectMgr;
                newNode = projectContainer.AddNestedProjectFromTemplate(fileName, destination, projectName, null, __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_CLONEFILE);
            }
            if (newNode == null)
            {
                return(null);
            }

            // Now that the sub project was created, get its extensibility object so we can return it
            object newProject = null;

            if (ErrorHandler.Succeeded(newNode.NestedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out newProject)))
            {
                return(newProject as EnvDTE.Project);
            }
            else
            {
                return(null);
            }
        }
コード例 #10
0
        private void VerifyNestedProjectRename(ProjectNode project, NestedProjectNode nestedProject, IVsHierarchy nestedHierarchy, string testName)
        {
            Assert.IsTrue(nestedProject.Caption == testName, "Failed to rename the nested project to " + testName);

            string nestedProjectPath;

            ((IVsProject3)nestedHierarchy).GetMkDocument(VSConstants.VSITEMID_ROOT, out nestedProjectPath);

            Assert.IsTrue(NativeMethods.IsSamePath(nestedProject.Url, nestedProjectPath), "Failed to rename the nested project file to " + nestedProjectPath);

            MSBuild.Project buildProject = typeof(ProjectNode).GetProperty("BuildProject", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(project, new object[] { }) as MSBuild.Project;

            foreach (MSBuild.ProjectItem item in buildProject.Items)
            {
                if (String.Compare(item.ItemType, ProjectFileConstants.SubProject, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    string name = Path.GetFileNameWithoutExtension(item.EvaluatedInclude);
                    Assert.IsTrue(name == testName, "Failed to rename the nested project to " + testName);
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Evaluates the result of an add operation.
        /// </summary>
        /// <param name="result">The <paramref name="VSADDRESULT"/> returned by the Add methods</param>
        /// <param name="path">The full path of the item added.</param>
        /// <returns>A ProjectItem object.</returns>
        protected virtual EnvDTE.ProjectItem EvaluateAddResult(VSADDRESULT result, string path)
        {
            return(UIThread.DoOnUIThread(delegate()
            {
                if (result == VSADDRESULT.ADDRESULT_Success)
                {
                    HierarchyNode nodeAdded = this.NodeWithItems.FindChild(path);
                    Debug.Assert(nodeAdded != null, "We should have been able to find the new element in the hierarchy");
                    if (nodeAdded != null)
                    {
                        EnvDTE.ProjectItem item = null;
                        FileNode fileNode = nodeAdded as FileNode;
                        if (fileNode != null)
                        {
                            item = new OAFileItem(this.Project, fileNode);
                        }
                        else
                        {
                            NestedProjectNode projectNode = nodeAdded as NestedProjectNode;
                            if (projectNode != null)
                            {
                                item = new OANestedProjectItem(this.Project, projectNode);
                            }
                            else
                            {
                                item = new OAProjectItem <HierarchyNode>(this.Project, nodeAdded);
                            }
                        }

                        this.Items.Add(item);
                        return item;
                    }
                }
                return null;
            }));
        }
コード例 #12
0
        /// <summary>
        /// Reloads a nested project node by deleting it and readding it.
        /// </summary>
        /// <param name="node">The node to reload.</param>
        /*protected, but public for FSharp.Project.dll*/
        public virtual void ReloadNestedProjectNode(NestedProjectNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;

            if (solution == null)
            {
                throw new InvalidOperationException();
            }

            NestedProjectNode newNode = null;
            try
            {
                // (VS 2005 UPDATE) When deleting and re-adding the nested project,
                // we do not want SCC to see this as a delete and add operation.
                this.EventTriggeringFlag = ProjectNode.EventTriggering.DoNotTriggerTrackerEvents;

                // notify SolutionEvents listeners that we are about to add children
                IVsFireSolutionEvents fireSolutionEvents = solution as IVsFireSolutionEvents;

                if (fireSolutionEvents == null)
                {
                    throw new InvalidOperationException();
                }

                ErrorHandler.ThrowOnFailure(fireSolutionEvents.FireOnBeforeUnloadProject(node.NestedHierarchy));

                int isDirtyAsInt = 0;
                this.IsDirty(out isDirtyAsInt);

                bool isDirty = (isDirtyAsInt == 0) ? false : true;

                ProjectElement element = node.ItemNode;
                node.CloseNestedProjectNode();

                // Remove from the solution
                this.RemoveChild(node);

                // Now readd it
                try
                {
                    __VSCREATEPROJFLAGS flags = __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_OPENFILE;
                    newNode = this.AddExistingNestedProject(element, flags);
                    newNode.AddVirtualProject();
                }
                catch (Exception e)
                {
                    // We get a System.Exception if anything failed, thus we have no choice but catch it.
                    // Exceptions are digested by VS. Show the error if not in automation.
                    if (!Utilities.IsInAutomationFunction(this.Site))
                    {
                        string message = (String.IsNullOrEmpty(e.Message)) ? SR.GetString(SR.NestedProjectFailedToReload, CultureInfo.CurrentUICulture) : e.Message;
                        string title = string.Empty;
                        OLEMSGICON icon = OLEMSGICON.OLEMSGICON_CRITICAL;
                        OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                        OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                        VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton);
                    }

                    // Do not digest exception. let the caller handle it. If in a later stage this exception is not digested then the above messagebox is not needed.
                    throw e;
                }

            #if DEBUG
                IVsHierarchy nestedHierarchy;
                solution.GetProjectOfUniqueName(newNode.GetMkDocument(), out nestedHierarchy);
                Debug.Assert(nestedHierarchy != null && Utilities.IsSameComObject(nestedHierarchy, newNode.NestedHierarchy), "The nested hierrachy was not reloaded correctly.");
            #endif
                this.SetProjectFileDirty(isDirty);

                fireSolutionEvents.FireOnAfterLoadProject(newNode.NestedHierarchy);
            }
            finally
            {
                // In this scenario the nested project failed to unload or reload the nested project. We will unload the whole project, otherwise the nested project is lost.
                // This is similar to the scenario when one wants to open a project and the nested project cannot be loaded because for example the project file has xml errors.
                // We should note that we rely here that if the unload fails then exceptions are not digested and are shown to the user.
                if (newNode == null || newNode.NestedHierarchy == null)
                {
                    solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject | (uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave, this, 0);
                }
                else
                {
                    this.EventTriggeringFlag = ProjectNode.EventTriggering.TriggerAll;
                }
            }
        }
コード例 #13
0
 internal VisualStudio_Project_Samples_NestedProjectNodeAccessor(NestedProjectNode target) :
     base(target, m_privateType)
 {
 }
コード例 #14
0
 /// <summary>
 /// Creates a new project by cloning an existing template project.
 /// </summary>
 /// <returns></returns>
 protected override ProjectNode CreateProject()
 {
     NestedProjectNode project = new NestedProjectNode();
     project.SetSite((IOleServiceProvider)((IServiceProvider)this.Package).GetService(typeof(IOleServiceProvider)));
     return project;
 }
コード例 #15
0
        public void ProjectTypeTest()
        {
            NestedProjectNode target = new NestedProjectNode();

            string val = typeof(NestedProjectNode).Name;

            Assert.AreEqual(val, target.ProjectType, "Microsoft.VisualStudio.Project.Samples.NestedProject.NestedProjectNode.ProjectType was not " +
                    "set correctly.");
        }
コード例 #16
0
 public void ConstructorTest()
 {
     NestedProjectNode target = new NestedProjectNode();
     Assert.IsNotNull(target, "Failed to initialize new instance of NestedProjectNode");
 }
コード例 #17
0
        public void GetPriorityProjectDesignerPagesTest()
        {
            NestedProjectNode target = new NestedProjectNode();
            VisualStudio_Project_Samples_NestedProjectNodeAccessor accessor =
                new VisualStudio_Project_Samples_NestedProjectNodeAccessor(target);


            Guid[] actual;
            actual = accessor.GetPriorityProjectDesignerPages();

            Assert.IsTrue(actual != null && actual.Length > 0, "The result of GetConfigurationIndependentPropertyPages was unexpected.");
            Assert.IsTrue(actual[0].Equals(typeof(GeneralPropertyPage).GUID), "The value of collection returned by GetConfigurationIndependentPropertyPages is unexpected.");
        }
コード例 #18
0
        public void GetFormatListTest()
        {
            NestedProjectNode target = new NestedProjectNode();

            string ppszFormatList;

            int expected = VSConstants.S_OK;
            int actual;

            actual = target.GetFormatList(out ppszFormatList);

            Assert.IsFalse(String.IsNullOrEmpty(ppszFormatList), "[out] ppszFormatList in GetFormatList() method was not set correctly.");
            Assert.AreEqual(expected, actual, "Microsoft.VisualStudio.Project.Samples.NestedProject.NestedProjectNode.GetFormatList did no" +
                    "t return the expected value.");
        }
コード例 #19
0
        public void ConstructorTest()
        {
            NestedProjectNode target = new NestedProjectNode();

            Assert.IsNotNull(target, "Failed to initialize new instance of NestedProjectNode");
        }
コード例 #20
0
        public void AddFileFromTemplateTest()
        {
            NestedProjectNode target = projectNode;

            target.AddFileFromTemplate(fullPathToClassTemplateFile, fullPathToTargetFile);
        }