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"); }); }
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; } })); }
public void ProjectGuidTest() { NestedProjectNode target = projectNode; Guid val = new Guid(GuidStrings.GuidNestedProjectFactory); Assert.AreEqual(val, target.ProjectGuid, "NestedProjectNode.ProjectGuid was not set correctly."); }
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."); }
public void GetAutomationObjectTest() { NestedProjectNode target = projectNode; object actual = target.GetAutomationObject(); Assert.IsNotNull(actual, "Failed to initialize an AutomationObject for " + "NestedProjectNode within GetAutomationObject method"); }
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."); }
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."); }
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."); }
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); } }
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); } } }
/// <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; })); }
/// <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; } } }
internal VisualStudio_Project_Samples_NestedProjectNodeAccessor(NestedProjectNode target) : base(target, m_privateType) { }
/// <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; }
public void ConstructorTest() { NestedProjectNode target = new NestedProjectNode(); Assert.IsNotNull(target, "Failed to initialize new instance of NestedProjectNode"); }
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."); }
public void AddFileFromTemplateTest() { NestedProjectNode target = projectNode; target.AddFileFromTemplate(fullPathToClassTemplateFile, fullPathToTargetFile); }