/// <summary> /// Constructor for the FolderNode /// </summary> /// <param name="root">Root node of the hierarchy</param> /// <param name="relativePath">relative path from root i.e.: "NewFolder1\\NewFolder2\\NewFolder3</param> /// <param name="element">Associated project element</param> public FolderNode(ProjectNode root, string relativePath, ProjectElement element) : base(root, element) { if (relativePath == null) { throw new ArgumentNullException("relativePath"); } VirtualNodeName = relativePath.TrimEnd('\\'); }
private ProjectElement GetProjectElementBasedOnInputFromComponentSelectorData() { var element = new ProjectElement(ProjectMgr, typeName, ProjectFileConstants.COMReference); // Set the basic information regarding this COM component element.SetMetadata(ProjectFileConstants.Guid, typeGuid.ToString("B")); element.SetMetadata(ProjectFileConstants.VersionMajor, majorVersionNumber); element.SetMetadata(ProjectFileConstants.VersionMinor, minorVersionNumber); element.SetMetadata(ProjectFileConstants.Lcid, LCID); element.SetMetadata(ProjectFileConstants.Isolated, false.ToString()); // See if a PIA exist for this component var typelib = new TypeLibConverter(); string assemblyName; string assemblyCodeBase; if (typelib.GetPrimaryInteropAssembly(typeGuid, int.Parse(majorVersionNumber, CultureInfo.InvariantCulture), int.Parse(minorVersionNumber, CultureInfo.InvariantCulture), int.Parse(LCID, CultureInfo.InvariantCulture), out assemblyName, out assemblyCodeBase)) { element.SetMetadata(ProjectFileConstants.WrapperTool, WrapperToolAttributeValue.Primary.ToString().ToLowerInvariant()); } else { // MSBuild will have to generate an interop assembly element.SetMetadata(ProjectFileConstants.WrapperTool, WrapperToolAttributeValue.TlbImp.ToString().ToLowerInvariant()); element.SetMetadata(ProjectFileConstants.EmbedInteropTypes, true.ToString()); element.SetMetadata(ProjectFileConstants.Private, true.ToString()); } return element; }
/// <summary> /// Constructor for the ComReferenceNode. /// </summary> public ComReferenceNode(ProjectNode root, ProjectElement element) : base(root, element) { typeName = ItemNode.GetMetadata(ProjectFileConstants.Include); var typeGuidAsString = ItemNode.GetMetadata(ProjectFileConstants.Guid); if (typeGuidAsString != null) { typeGuid = new Guid(typeGuidAsString); } majorVersionNumber = ItemNode.GetMetadata(ProjectFileConstants.VersionMajor); minorVersionNumber = ItemNode.GetMetadata(ProjectFileConstants.VersionMinor); LCID = ItemNode.GetMetadata(ProjectFileConstants.Lcid); SetProjectItemsThatRelyOnReferencesToBeResolved(false); SetInstalledFilePath(); }
/// <summary> /// Links a reference node to the project and hierarchy. /// </summary> protected override void BindReferenceData() { Debug.Assert(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 (ItemNode == null || ItemNode.Item == null) { ItemNode = new ProjectElement(ProjectMgr, assemblyName.FullName, ProjectFileConstants.Reference); } // Set the basic information we know about ItemNode.SetMetadata(ProjectFileConstants.Name, assemblyName.Name); if (!string.IsNullOrEmpty(assemblyPath)) { ItemNode.SetMetadata(ProjectFileConstants.AssemblyName, Path.GetFileName(assemblyPath)); } else { ItemNode.SetMetadata(ProjectFileConstants.AssemblyName, null); } SetReferenceProperties(); }
/// <summary> /// Based on the Template and TypeGuid properties of the /// element, generate the full template path. /// TypeGuid should be the Guid of a registered project factory. /// Template can be a full path, a project template (for projects /// that support VsTemplates) or a relative path (for other projects). /// </summary> protected virtual string GetProjectTemplatePath(ProjectElement element) { var elementToUse = element == null ? nestedProjectElement : element; if (elementToUse == null) { throw new ArgumentNullException("element"); } var templateFile = elementToUse.GetMetadata(ProjectFileConstants.Template); Debug.Assert(!string.IsNullOrEmpty(templateFile), "No template file has been specified in the template attribute in the project file"); var fullPath = templateFile; if (!Path.IsPathRooted(templateFile)) { var registeredProjectType = GetRegisteredProject(elementToUse); // This is not a full path Debug.Assert( registeredProjectType != null && (!string.IsNullOrEmpty(registeredProjectType.DefaultProjectExtensionValue) || !string.IsNullOrEmpty(registeredProjectType.WizardTemplatesDirValue)), " Registered wizard directory value not set in the registry."); // See if this specify a VsTemplate file fullPath = registeredProjectType.GetVsTemplateFile(templateFile); if (string.IsNullOrEmpty(fullPath)) { // Default to using the WizardTemplateDir to calculate the absolute path fullPath = Path.Combine(registeredProjectType.WizardTemplatesDirValue, templateFile); } } return fullPath; }
/// <summary> /// This can be called directly or through RunVsTemplateWizard. /// This will clone a template project file and add it as a /// subproject to our hierarchy. /// If you want to create a project for which there exist a /// vstemplate, consider using RunVsTemplateWizard instead. /// </summary> protected internal virtual NestedProjectNode AddNestedProjectFromTemplate(string fileName, string destination, string projectName, ProjectElement element, __VSCREATEPROJFLAGS creationFlags) { // If this is project creation and the template specified a subproject in its project file, this.nestedProjectElement will be used var elementToUse = element == null ? nestedProjectElement : element; if (elementToUse == null) { // If this is null, this means MSBuild does not know anything about our subproject so add an MSBuild item for it elementToUse = new ProjectElement(this, fileName, ProjectFileConstants.SubProject); } var node = CreateNestedProjectNode(elementToUse); node.Init(fileName, destination, projectName, creationFlags); // In case that with did not have an existing element, or the nestedProjectelement was null // and since Init computes the final path, set the MSBuild item to that path if (nestedProjectElement == null) { var relativePath = node.Url; if (Path.IsPathRooted(relativePath)) { relativePath = ProjectFolder; if (!relativePath.EndsWith("/\\", StringComparison.Ordinal)) { relativePath += Path.DirectorySeparatorChar; } relativePath = new Url(relativePath).MakeRelative(new Url(node.Url)); } elementToUse.Rename(relativePath); } AddChild(node); return node; }
protected internal void RunVsTemplateWizard(ProjectElement element, bool silent) { var elementToUse = element == null ? nestedProjectElement : element; if (elementToUse == null) { throw new ArgumentNullException("element"); } nestedProjectElement = elementToUse; var oaProject = GetAutomationObject() as OAProject; if (oaProject == null || oaProject.ProjectItems == null) throw new InvalidOperationException(SR.GetString(SR.InvalidAutomationObject, CultureInfo.CurrentUICulture)); Debug.Assert(oaProject.Object != null, "The project automation object should have set the Object to the SolutionFolder"); var folder = oaProject.Object as OASolutionFolder<ProjectContainerNode>; // Prepare the parameters to pass to RunWizardFile var destination = elementToUse.GetFullPathForElement(); var template = GetProjectTemplatePath(elementToUse); var wizParams = new object[7]; wizParams[0] = Constants.vsWizardAddSubProject; wizParams[1] = Path.GetFileNameWithoutExtension(destination); wizParams[2] = oaProject.ProjectItems; wizParams[3] = Path.GetDirectoryName(destination); wizParams[4] = Path.GetFileNameWithoutExtension(destination); wizParams[5] = Path.GetDirectoryName(folder.DTE.FullName); //VS install dir wizParams[6] = silent; var wizardTrust = GetService(typeof (SVsDetermineWizardTrust)) as IVsDetermineWizardTrust; if (wizardTrust != null) { var guidProjectAdding = Guid.Empty; // In case of a project template an empty guid should be added as the guid parameter. See env\msenv\core\newtree.h IsTrustedTemplate method definition. ErrorHandler.ThrowOnFailure(wizardTrust.OnWizardInitiated(template, ref guidProjectAdding)); } try { // Make the call to execute the wizard. This should cause AddNestedProjectFromTemplate to be // called back with the correct set of parameters. var extensibilityService = (IVsExtensibility) GetService(typeof (IVsExtensibility)); var result = extensibilityService.RunWizardFile(template, 0, ref wizParams); if (result == wizardResult.wizardResultFailure) throw new COMException(); } finally { if (wizardTrust != null) { ErrorHandler.ThrowOnFailure(wizardTrust.OnWizardCompleted()); } } }
/// <summary> /// This is used when loading the project to loop through all the items /// and for each SubProject it finds, it create the project and a node /// in our Hierarchy to hold the project. /// </summary> protected internal void CreateNestedProjectNodes() { // 1. Create a ProjectElement with the found item and then Instantiate a new Nested project with this ProjectElement. // 2. Link into the hierarchy. // Read subprojects from from msbuildmodel var creationFlags = __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT; if (IsNewProject) { creationFlags |= __VSCREATEPROJFLAGS.CPF_CLONEFILE; } else { creationFlags |= __VSCREATEPROJFLAGS.CPF_OPENFILE; } foreach (var item in BuildProject.Items) { if ( string.Compare(item.ItemType, ProjectFileConstants.SubProject, StringComparison.OrdinalIgnoreCase) == 0) { nestedProjectElement = new ProjectElement(this, item, false); if (!IsNewProject) { AddExistingNestedProject(null, creationFlags); } else { // If we are creating the subproject from a vstemplate/vsz file var isVsTemplate = Utilities.IsTemplateFile(GetProjectTemplatePath(null)); if (isVsTemplate) { RunVsTemplateWizard(null, true); } else { // We are cloning the specified project file AddNestedProjectFromTemplate(null, creationFlags); } } } } nestedProjectElement = null; }
/// <summary> /// Creates a com reference node from the project element. /// </summary> protected virtual ComReferenceNode CreateComReferenceNode(ProjectElement reference) { return new ComReferenceNode(ProjectMgr, reference); }
/// <summary> /// Creates an assembly refernce node from a project element. /// </summary> protected virtual AssemblyReferenceNode CreateAssemblyReferenceNode(ProjectElement element) { AssemblyReferenceNode node = null; try { node = new AssemblyReferenceNode(ProjectMgr, element); } catch (ArgumentNullException e) { Trace.WriteLine("Exception : " + e.Message); } catch (FileNotFoundException e) { Trace.WriteLine("Exception : " + e.Message); } catch (BadImageFormatException e) { Trace.WriteLine("Exception : " + e.Message); } catch (FileLoadException e) { Trace.WriteLine("Exception : " + e.Message); } catch (SecurityException e) { Trace.WriteLine("Exception : " + e.Message); } return node; }
/// <summary> /// Creates a project reference node given an existing project element. /// </summary> protected virtual ProjectReferenceNode CreateProjectReferenceNode(ProjectElement element) { return new ProjectReferenceNode(ProjectMgr, element); }
protected virtual ReferenceNode CreateReferenceNode(string referenceType, ProjectElement element) { ReferenceNode node = null; if (referenceType == ProjectFileConstants.COMReference) { node = CreateComReferenceNode(element); } else if (referenceType == ProjectFileConstants.Reference) { node = CreateAssemblyReferenceNode(element); } else if (referenceType == ProjectFileConstants.ProjectReference) { node = CreateProjectReferenceNode(element); } return node; }
/// <summary> /// Adds references to this container from a MSBuild project. /// </summary> public void LoadReferencesFromBuildProject(MSBuild.Project buildProject) { foreach (var referenceType in SupportedReferenceTypes) { IEnumerable<MSBuild.ProjectItem> refererncesGroup = ProjectMgr.BuildProject.GetItems(referenceType); var isAssemblyReference = referenceType == ProjectFileConstants.Reference; // If the project was loaded for browsing we should still create the nodes but as not resolved. if (isAssemblyReference && ProjectMgr.Build(MsBuildTarget.ResolveAssemblyReferences) != MSBuildResult.Successful) { continue; } foreach (var item in refererncesGroup) { var element = new ProjectElement(ProjectMgr, item, false); var 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" /> var found = false; for (var n = FirstChild; n != null && !found; n = n.NextSibling) { if (string.Compare(n.Caption, node.Caption, StringComparison.OrdinalIgnoreCase) == 0) { found = true; } } if (!found) { AddChild(node); } } } } }
/// <summary> /// constructor for the ReferenceNode /// </summary> protected ReferenceNode(ProjectNode root, ProjectElement element) : base(root, element) { ExcludeNodeFromScc = true; }
public ProjectReferenceNode(ProjectNode root, ProjectElement element) : base(root, element) { referencedProjectRelativePath = ItemNode.GetMetadata(ProjectFileConstants.Include); Debug.Assert(!string.IsNullOrEmpty(referencedProjectRelativePath), "Could not retrive referenced project path form project file"); var guidString = ItemNode.GetMetadata(ProjectFileConstants.Project); // Continue even if project setttings cannot be read. try { referencedProjectGuid = new Guid(guidString); buildDependency = new BuildDependency(ProjectMgr, referencedProjectGuid); ProjectMgr.AddBuildDependency(buildDependency); } finally { Debug.Assert(referencedProjectGuid != Guid.Empty, "Could not retrive referenced project guidproject file"); ReferencedProjectName = ItemNode.GetMetadata(ProjectFileConstants.Name); Debug.Assert(!string.IsNullOrEmpty(ReferencedProjectName), "Could not retrive referenced project name form project file"); } var uri = new Uri(ProjectMgr.BaseURI.Uri, referencedProjectRelativePath); if (uri != null) { referencedProjectFullPath = Microsoft.VisualStudio.Shell.Url.Unescape(uri.LocalPath, true); } }
public NestedProjectNode(ProjectNode root, ProjectElement element) : base(root, element) { IsExpanded = true; }
/// <summary> /// Links a reference node to the project file. /// </summary> protected override void BindReferenceData() { Debug.Assert(!string.IsNullOrEmpty(ReferencedProjectName), "The referencedProjectName field has not been initialized"); Debug.Assert(referencedProjectGuid != Guid.Empty, "The referencedProjectName field has not been initialized"); ItemNode = new ProjectElement(ProjectMgr, referencedProjectRelativePath, ProjectFileConstants.ProjectReference); ItemNode.SetMetadata(ProjectFileConstants.Name, ReferencedProjectName); ItemNode.SetMetadata(ProjectFileConstants.Project, referencedProjectGuid.ToString("B")); ItemNode.SetMetadata(ProjectFileConstants.Private, true.ToString()); }
/// <summary> /// Creates the file node. /// </summary> /// <param name="item">The project element item.</param> /// <returns></returns> public override FileNode CreateFileNode(ProjectElement item) { TeXProjectFileNode node = new TeXProjectFileNode(this, item); node.OleServiceProvider.AddService(typeof(EnvDTE.Project), new OleServiceProvider.ServiceCreatorCallback(this.CreateServices), false); node.OleServiceProvider.AddService(typeof(ProjectItem), node.ServiceCreator, false); node.OleServiceProvider.AddService(typeof(VSProject), new OleServiceProvider.ServiceCreatorCallback(this.CreateServices), false); return node; }
/// <summary> /// Add an existing project as a nested node of our hierarchy. /// This is used while loading the project and can also be used /// to add an existing project to our hierarchy. /// </summary> protected internal virtual NestedProjectNode AddExistingNestedProject(ProjectElement element, __VSCREATEPROJFLAGS creationFlags) { var elementToUse = element == null ? nestedProjectElement : element; if (elementToUse == null) { throw new ArgumentNullException("element"); } var filename = elementToUse.GetFullPathForElement(); // Delegate to AddNestedProjectFromTemplate. Because we pass flags that specify open project rather then clone, this will works. Debug.Assert((creationFlags & __VSCREATEPROJFLAGS.CPF_OPENFILE) == __VSCREATEPROJFLAGS.CPF_OPENFILE, "__VSCREATEPROJFLAGS.CPF_OPENFILE should have been specified, did you mean to call AddNestedProjectFromTemplate?"); return AddNestedProjectFromTemplate(filename, Path.GetDirectoryName(filename), Path.GetFileName(filename), elementToUse, creationFlags); }
/// <summary> /// Initializes a new instance of the <see cref="TeXProjectFileNode"/> class. /// </summary> /// <param name="root">The project node.</param> /// <param name="e">The project element node.</param> internal TeXProjectFileNode(ProjectNode root, ProjectElement e) : base(root, e) { }
/// <summary> /// This will clone a template project file and add it as a /// subproject to our hierarchy. /// If you want to create a project for which there exist a /// vstemplate, consider using RunVsTemplateWizard instead. /// </summary> protected internal virtual NestedProjectNode AddNestedProjectFromTemplate(ProjectElement element, __VSCREATEPROJFLAGS creationFlags) { var elementToUse = element == null ? nestedProjectElement : element; if (elementToUse == null) { throw new ArgumentNullException("element"); } var destination = elementToUse.GetFullPathForElement(); var template = GetProjectTemplatePath(elementToUse); return AddNestedProjectFromTemplate(template, Path.GetDirectoryName(destination), Path.GetFileName(destination), elementToUse, creationFlags); }
/// <summary> /// Constructor for the FileNode /// </summary> /// <param name="root">Root of the hierarchy</param> /// <param name="e">Associated project element</param> public FileNode(ProjectNode root, ProjectElement element) : base(root, element) { if (ProjectMgr.NodeHasDesigner(ItemNode.GetMetadata(ProjectFileConstants.Include))) { HasDesigner = true; } }
/// <summary> /// Override this method if you want to provide your own type of nodes. /// This would be the case if you derive a class from NestedProjectNode /// </summary> protected virtual NestedProjectNode CreateNestedProjectNode(ProjectElement element) { return new NestedProjectNode(this, element); }
/// <summary> /// Constructor for the DependentFileNode /// </summary> /// <param name="root">Root of the hierarchy</param> /// <param name="e">Associated project element</param> public DependentFileNode(ProjectNode root, ProjectElement element) : base(root, element) { HasParentNodeNameRelation = false; }
/// <summary> /// Get information from the registry based for the project /// factory corresponding to the TypeGuid of the element /// </summary> private RegisteredProjectType GetRegisteredProject(ProjectElement element) { var elementToUse = element == null ? nestedProjectElement : element; if (elementToUse == null) { throw new ArgumentNullException("element"); } // Get the project type guid from project elementToUse var typeGuidString = elementToUse.GetMetadataAndThrow(ProjectFileConstants.TypeGuid, new Exception()); var projectFactoryGuid = new Guid(typeGuidString); var dte = ProjectMgr.Site.GetService(typeof (DTE)) as DTE; Debug.Assert(dte != null, "Could not get the automation object from the services exposed by this project"); if (dte == null) throw new InvalidOperationException(); var registeredProjectType = RegisteredProjectType.CreateRegisteredProjectType(projectFactoryGuid); Debug.Assert(registeredProjectType != null, "Could not read the registry setting associated to this project."); if (registeredProjectType == null) { throw new InvalidOperationException(); } return registeredProjectType; }
/// <summary> /// Constructor for the ReferenceNode /// </summary> public AssemblyReferenceNode(ProjectNode root, ProjectElement element) : base(root, element) { GetPathNameFromProjectFile(); InitializeFileChangeEvents(); var include = ItemNode.GetMetadata(ProjectFileConstants.Include); CreateFromAssemblyName(new AssemblyName(include)); }