GetVSTemplateFile() public method

If the project support VsTemplates, returns the path to the vstemplate file corresponding to the requested template You can pass in a string such as: "Windows\Console Application"
public GetVSTemplateFile ( string templateFile ) : string
templateFile string
return string
Esempio n. 1
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);
        }