How to organize your custom templates in VS 2008

Visual Studio providing a feature called Custom Template to create our own project templates(Web,Windows etc,.) and Item templates(Web Form,Class file etc,.). These Templates are used to add/deploy all prerequisities to specified project.
Organizing your custom templates are very easy in VS,we can create our own custome folder with hierarchy for projects and items. Refer the following steps to do organize your custom templates.

  1. Create your sample template contents and sample.vstemplate file
  2. Create sample.vscontent file and add your custom folder name in ProjectSubType attribute node to organize your template.Refer the following Sample.vscontent file
    Ex:
    <?xml version="1.0" encoding="utf-8"?>
    <VSContent xmlns="http://schemas.microsoft.com/developer/vscontent/2005">
    <Content>
    <FileName>SampleTemplate.zip</FileName>
    <DisplayName>Sample Test Template</DisplayName>
    <Description>Sample Template</Description>
    <FileContentType>VSTemplate</FileContentType>
    <ContentVersion>1.0</ContentVersion>
    <Attributes>
    <Attribute name="ProjectType" value="Visual C#" />
    <Attribute name="ProjectSubType" value="Sample"/>
    <Attribute name="TemplateType" value="Project"/>
    </Attributes>
    </Content>
    </VSContent>
    
    If you want add sub folder then mention same thing in ProjectSubType like Parent\child1\child2 etc. Refer the following Sample.vstemplate file
    <?xml version="1.0" encoding="utf-8"?>
    <VSContent xmlns="http://schemas.microsoft.com/developer/vscontent/2005">
    <Content>
    <FileName>SampleTemplate.zip</FileName>
    <DisplayName>Sample Test Template</DisplayName>
    <Description>Sample Template</Description>
    <FileContentType>VSTemplate</FileContentType>
    <ContentVersion>1.0</ContentVersion>
    <Attributes>
    <Attribute name="ProjectType" value="Visual C#" />
    <Attribute name="ProjectSubType" value="Sample\Child1"/>
    <Attribute name="TemplateType" value="Project"/>
    </Attributes>
    </Content>
    </VSContent>
    
  3. Install your Sample.vscontent file


  4. Open a Visual studio,go to New -> Project,now you can able to your folder hierarchy just like you mentioned in the vscontent file.


Build Action:

A Visual Studio Porject can contains different types of files like code files,normal resource files,embedded resource files, help files etc,each type will have different build action on VS, based on this VS will do the required action on these file i.e code can be compiled and added to assembly, embedded resource file will add to assembly without compile, no action for help files etc. In templates we can set the VS build action for a project item while we creating it. Follow the following steps to apply build action on your project item,

  1. Open your Sample.vstemplate file.
  2. Add ItemType attribute to ProjectItem tag with required Build action.

    Ex:
    
    <ProjectItem ItemType="None" ReplaceParameters="true" TargetFileName="Sample.cs">Sample.cs</ProjectItem>
    
  3. Install your current tempalte.
  4. Open/add project in Visual Studio then add a new item which you created just now and check the build action from the properties of created item.
If you feel free send your feedbacks to eshock.vasan@gmail.com


Powered by Blogger.

About

About

Follow us

Popular Posts