RAD Studio (Common)
ContentsIndex
PreviousUpNext
Creating Template Libraries

Template libraries are custom project templates that specify how a project should look and what it should contain. When you create a custom template library, it is placed in the New Files dialog box where is accessible for creating a project using FileNew.  

You can create template library projects from scratch, or you can use projects previously created by you or other developers as the basis for template libraries. To use an existing project, you simply create an XML file with the extension .bdstemplatelib which describes the project and is used to create the template library using that project.

Note: When creating a project to use with a template library, the project should be located in a subdirectory that contains no other projects. Also, all of the files that are in the project should be located within the subdirectory or its child subdirectories.

To create a Template Library

  1. Create a new project or open an existing project which will be the basis for the custom template library. Make any modifications to the project to customize it for the template library.
  2. Save and close the project.
  3. Choose FileNewOtherWebDocuments and double-click the XML File icon.
  4. Replace the default contents of the new XML file with the following sample content:

<TemplateLibrary Version="1.0" id="">
  <Name><Name/>
  <Description><Description/>
  <Items>
   <Item id="" Creator="">
      <Name>Name of template library here <Name/>
      <Description>Custom Project Template<Description/>
   <Author><Author/>
   <Icon>MyTemplate\MyTemplateIcon.ico<Icon/>
        <Projectfile>MyTemplate.dproj</Projectfile>
       <DefaultProjectName>MyTemplate<DefaultProjectName/>
    <FilePath>MyTemplate<FilePath/>
    </Item>
  </Items>
</TemplateLibrary>

Important:

  • The id="" attribute of the <TemplateLibrary> element should be something unique to avoid conflicts with other template libraries. A good practice is to include your name or the name of your company as part of the id.
  • The Creator="" attribute in the <Item> element specifies which page of the New Items dialog box displays the icon for this template library. You can put the project icon on a specific page for the type of project it creates. Below are the possible Creator="" attribute values:

Project Type 
Item Creator Attribute Value 
C++ Projects  
Creator="CBuilderProjectRepositoryCreator"  
Delphi Projects  
Creator="DelphiProjectRepositoryCreator"  
Delphi for .NET Projects  
Creator="DelphiDotNetProjectRepositoryCreator"  
Delphi for ASP .NET Projects  
Creator="AspDelphiProjectRepositoryCreator"  

  1. Save the .bdstemplatelib.xml file to a directory above the project directory.
    Note: The <FilePath> element in the .bdstemplatelib file indicates the location of the project directory relative to the location of the .bdstemplatelib file.
  2. Edit the.bdstemplatelib.xml content to customize it for your own template library:
    • Add the template library name, description, and Creator attribute value.
    • Edit the project name, project path information, icon path, and file name. Optionally, you can add your name as author.
    • Specify the relative path to the .bdstemplatelib.xml in the <FilePath> value. For example, if your project is in C:\MyProjects\TemplateLibraries\MyTemplate, and you put the XML file in C:\MyProjects\TemplateLibraries, the <FilePath> value in the XML file would be <FilePath>TemplateLibraries\MyTemplate</FilePath>.
  3. Choose ToolsTemplateLibraries to open the Template Libraries dialog box.
  4. Click the Add button, browse to and select the .bdstemplatelib.xml file you just created, and click Open. The new template library is added to the list in the Template Libraries dialog box. It is also added to the specified page of the New Files dialog box. Click OK to close the Template Libraries dialog box.
To use this template library for creating a new project, choose FileNewOther, and select your template library in the New files dialog box. 

Example  

<TemplateLibrary Version="1.0" id="CompanyXYZASPWebSiteProject">
  <Name>ASPWebSiteProject<Name/>
  <Description>ASP.NET WebSite Project Template<Description/>
  <Items>
   <Item id="ASPWebSiteProject" Creator="AspDelphiProjectRepositoryCreator">
      <Name>ASP.NET WebSite Project<Name/>
      <Description>ASP.NET WebSite<Description/>
   <Author>John Smith<Author/>
   <Icon>ASPWebsiteProject\ASPWebsiteProjectIcon.ico<Icon/>
        <Projectfile>ASPWebSiteProject.dproj</Projectfile>
       <DefaultProjectName>ASPWebSiteProject<DefaultProjectName/>
    <FilePath>ASPWebSiteProject<FilePath/>
    </Item>
  </Items>
</TemplateLibrary>

If you have several related projects, you can use a single .bdstemplatelib template library file to list all the projects.

To combine multiple projects in one template library file

  1. Put all the project folders at the same level in the same project sub-folder.
  2. Create the .bdstemplatelib template library file at the level above the folder containing all the projects.
  3. Add the content for the first project as described above.
  4. Add an additional <Item></Item> to the <Items></Items> element for each project in the group, giving each <Item></Item> a unique id=" attribute.
Example

<TemplateLibrary Version="1.0" id="CodeGearASPWebSiteProject">
  <Name>ASPWebSiteProject<Name/>
  <Description>ASP.NET WebSite Project Template<Description/>
  <Items>
    <Item id="ASPWebSiteProject" Creator="AspDelphiProjectRepositoryCreator">
      <Name>ASP.NET WebSite Project<Name/>
      <Description>ASP.NET WebSite Project<Description/>
      <Author>CodeGear<Author/>     
      <Icon>ASPWebsiteProject\ASPWebsiteProjectIcon.ico<Icon/>
      <Projectfile>ASPWebSiteProject.dproj</Projectfile>            
      <DefaultProjectName>ASPWebSiteProject<DefaultProjectName/>
      <FilePath>ASPWebSiteProject<FilePath/>          
    </Item>
    <Item id="ASPWebSiteProjectMP" Creator="AspDelphiProjectRepositoryCreator">
       <Name>ASP.NET WebSite Project Master Page<Name/>
       <Description>ASP.NET WebSite Project Master Page<Description/>
      <Author>CodeGear<Author/>
      <Icon>ASPWebsiteProjectMP\ASPWebsiteProjectMPIcon.ico<Icon/>
       <Projectfile>ASPWebSiteProjectMP.dproj</Projectfile>
       <DefaultProjectName>ASPWebSiteProjectMP<DefaultProjectName/>
      <FilePath>ASPWebSiteProjectMP<FilePath/>
    </Item>
    <Item id="ASPWebSiteProjectForm" Creator="AspDelphiProjectRepositoryCreator">
       <Name>ASP.NET WebSite Project Information Form<Name/>      
      <Description>ASP.NET WebSite Information Form<Description/>
      <Author>CodeGear<Author/>    
      <Icon>ASPWebsiteProjectForm\ASPWebsiteProjectFormIcon.ico<Icon/>
       <Projectfile>ASPWebSiteProjectForm.dproj</Projectfile>
      <DefaultProjectName>ASPWebSiteProjectForm<DefaultProjectName/>
      <FilePath>ASPWebSiteProjectForm<FilePath/>     
    </Item>
  </Items>
</TemplateLibrary>
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!