Gets registry settings from for a project.
Example #1
0
        /// <summary>
        /// Get information from the registry based for the project
        /// factory corresponding to the TypeGuid of the element
        /// </summary>
        private RegisteredProjectType GetRegisteredProject(ProjectElement element)
        {
            ProjectElement elementToUse = (element == null) ? this.nestedProjectElement : element;

            if (elementToUse == null)
            {
                throw new ArgumentNullException("element");
            }

            // Get the project type guid from project elementToUse
            string typeGuidString     = elementToUse.GetMetadataAndThrow(ProjectFileConstants.TypeGuid, new Exception());
            Guid   projectFactoryGuid = new Guid(typeGuidString);

            EnvDTE.DTE dte = this.ProjectMgr.Site.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            Debug.Assert(dte != null, "Could not get the automation object from the services exposed by this project");

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

            RegisteredProjectType 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);
        }
Example #2
0
        /// <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)
        {
            ProjectElement elementToUse = (element == null) ? this.nestedProjectElement : element;

            if (elementToUse == null)
            {
                throw new ArgumentNullException("element");
            }

            string templateFile = elementToUse.GetMetadata(ProjectFileConstants.Template);

            Debug.Assert(!String.IsNullOrEmpty(templateFile), "No template file has been specified in the template attribute in the project file");

            string fullPath = templateFile;

            if (!Path.IsPathRooted(templateFile))
            {
                RegisteredProjectType registeredProjectType = this.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);
        }
Example #3
0
        internal static RegisteredProjectType CreateRegisteredProjectType(Guid projectTypeGuid)
        {
            RegisteredProjectType registederedProjectType = null;

            using (RegistryKey rootKey = VSRegistry.RegistryRoot(__VsLocalRegistryType.RegType_Configuration))
            {
                if (rootKey == null)
                {
                    return(null);
                }

                string projectPath = "Projects\\" + projectTypeGuid.ToString("B");
                using (RegistryKey projectKey = rootKey.OpenSubKey(projectPath))
                {
                    if (projectKey == null)
                    {
                        return(null);
                    }

                    registederedProjectType = new RegisteredProjectType();
                    registederedProjectType.DefaultProjectExtensionValue = projectKey.GetValue(DefaultProjectExtension) as string;
                    registederedProjectType.ProjectTemplatesDirValue     = projectKey.GetValue(ProjectTemplatesDir) as string;
                    registederedProjectType.WizardTemplatesDirValue      = projectKey.GetValue(WizardsTemplatesDir) as string;
                    registederedProjectType.PackageGuidValue             = new Guid(projectKey.GetValue(Package) as string);
                }
            }

            return(registederedProjectType);
        }
        /// <summary>
        /// Get information from the registry based for the project
        /// factory corresponding to the TypeGuid of the element
        /// </summary>
        private RegisteredProjectType GetRegisteredProject(ProjectElement element)
        {
            ProjectElement elementToUse = (element == null) ? this.nestedProjectElement : element;

            if (elementToUse == null)
            {
                throw new ArgumentNullException("element");
            }

            // Get the project type guid from project elementToUse
            string typeGuidString     = elementToUse.GetMetadataAndThrow(ProjectFileConstants.TypeGuid, new Exception());
            Guid   projectFactoryGuid = new Guid(typeGuidString);

            return(ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                RegisteredProjectType 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;
            }));
        }
Example #5
0
        internal static RegisteredProjectType CreateRegisteredProjectType(Guid projectTypeGuid)
        {
            RegisteredProjectType registederedProjectType = null;

            using(RegistryKey rootKey = VSRegistry.RegistryRoot(__VsLocalRegistryType.RegType_Configuration))
            {
                if(rootKey == null)
                {
                    return null;
                }

                string projectPath = "Projects\\" + projectTypeGuid.ToString("B");
                using(RegistryKey projectKey = rootKey.OpenSubKey(projectPath))
                {
                    if(projectKey == null)
                    {
                        return null;
                    }

                    registederedProjectType = new RegisteredProjectType();
                    registederedProjectType.DefaultProjectExtensionValue = projectKey.GetValue(DefaultProjectExtension) as string;
                    registederedProjectType.ProjectTemplatesDirValue = projectKey.GetValue(ProjectTemplatesDir) as string;
                    registederedProjectType.WizardTemplatesDirValue = projectKey.GetValue(WizardsTemplatesDir) as string;
                    registederedProjectType.PackageGuidValue = new Guid(projectKey.GetValue(Package) as string);
                }
            }

            return registederedProjectType;
        }