During one of my recent projects while talking with a colleague we were discussing the fact that in each website we created we had to perform the same tasks over and over. We decided that it would be a good idea to create a template that could be used as a starting point for all future projects, including custom error pages, global.asax, app settings, connection strings, master pages, themes and user controls. After some research I found there are several useful examples on the Microsoft site on how to do this.

The basic steps for creating a c# website project template are:

  1. Set up a website as normal in visual studio with all the files you want to include.
  2. Navigate to C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\Web\CSharp\1033 and copy one of the existing templates zip files.
  3. Extract the zip file and copy the .vstemplate and .webproj files to the location of your own website.
  4. The existing .vstemplate might contain a lot of extra information but all you need to get up and running for the template data section is the following basic information

    <TemplateData>
            <Name>Template Website</Name>
            <Description>A simple Website template</Description>
            <Icon>icon.ico</Icon>
            <ProjectType>Web</ProjectType>
            <ProjectSubType>CSharp</ProjectSubType>
            <DefaultName>Template Website</DefaultName>
        </TemplateData>

  5. In the next section you must list all the files in your template site. For example

    <ProjectItem>App_Themes/Default/SkinFile.skin</ProjectItem>
    <ProjectItem>App_Themes/Default/StyleSheet.css</ProjectItem>
    <ProjectItem>App_Themes/Default/images/arrow.jpeg</ProjectItem>           
    <ProjectItem>Controls/HeaderUserControl.ascx</ProjectItem>
    <ProjectItem>Controls/HeaderUserControl.ascx.cs</ProjectItem>
    <ProjectItem>MasterPage/Global.master</ProjectItem>
    <ProjectItem>MasterPage/Global.master.cs</ProjectItem>

  6. Next zip up the files that you want to be included in the template website, including the .vstemplate and .webproject and copy them into the following location C:\Documents and Settings\YOURNAME\My Documents\Visual Studio 2005\Templates\ProjectTemplates\Visual Web Developer
  7. Now when you open Visual Studio 2005 if you go to add a new website you'll see your new template under 'My Templates'

Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist
posted @ Friday, March 14, 2008 1:58 PM | in Visual Studio 2005

Comments

No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  


Please add 4 and 4 and type the answer here: