Modify default templates for Visual Studio 2008

In Visual Studio we have the option of adding our own templates for any application type, be it windows application, web application, web service etc. I did not want to add my own templates as I wanted to change the default templates that are bundled with Visual Studio 2008. After researching on this case, I finally found out how we can achieve it.

I will choose the web as my platform. Visual Studio 2008 has two modes of creating a web application.

1. Web application project

2. Websites project.

Website project model:

Create a new website.

File --> New --> New website --> ASP.Net Web Site

Once we create a new project, it will automatically add the four items in the solution. App_data folder, Default.aspx, Default.aspx.cs and web.config file. These are the default templates which are installed along with the Visual Studio 2008. These templates are located in the WebApplication.Zip folder at:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplatesCache\Web\CSharp\1033\WebApplication.zip

File name: Default.aspx

Open the WebApplication.Zip folder. Make sure you have the backup of the folder. Edit the default.aspx in the notepad. Modify the contents of the file as per the requirement and save the files. Open the Visual Studio 2008 and create a new website project. Now you should see the modified file contents in the default.aspx file in Visual Studio 2008.

When we add the new item to the existing solution, the changes made on the default.aspx page does not reflect here. It only reflects the changes when we create a new website. This is expected because the location for the item template is different.

When we add the new item to the Visual Studio solution, we have multiple options.

· Add the new item and use the code behind page.

· Add the new item and use inline code.

· Add the new item and preset the master page.

For all the three options the templates used are taken from different template locations

Option1.

Add the new item with the code behind file and no master page. The option "Place code in separate file" is checked. Go to the below mentioned location and modify the code as per requirement.

C:\Program Files\Microsoft Visual Studio9.0\Common7\IDE\ItemTemplatesCache\Web\CSharp\1033\WebForm.zip

File name: WebForm_cb.aspx

Option2.

Add the new item without the code behind file (inline code) and no master page. The option "Place code in separate file" is unchecked. Go to the below mentioned location and modify the code as per requirement.

C:\Program Files\Microsoft Visual Studio9.0\Common7\IDE\ItemTemplatesCache\Web\CSharp\1033\WebForm.zip

File name: WebForm.aspx

Option3.

Add the new item without the code behind file (inline code) and with "Select master page" option checked. The option "Place code in separate file" is unchecked. Go to the below mentioned location and modify the code as per requirement.

C:\Program Files\Microsoft Visual Studio9.0\Common7\IDE\ItemTemplatesCache\Web\CSharp\1033\WebForm.zip

File name: ContentPage.aspx

Option4.

Add the new item with the code behind file and with "Select master page" option checked. The option "Place code in separate file" is checked. Go to the below mentioned location and modify the code as per requirement.

C:\Program Files\Microsoft Visual Studio9.0\Common7\IDE\ItemTemplatesCache\Web\CSharp\1033\WebForm.zip

File name: ContentPage_cb.aspx

Web application project model:

Create a new Web application project.

Go to ... File --> New --> Project --> Project type --> Visual C# -> Web --> ASP.Net Web Application

In case of the web application project, the Visual Studio 2008 adds many default items. Properties, AssemblyInfo.cs, References, App_Data, Default.aspx, default.aspx.cx, default.aspx.designer.cs and web.config file. These templates are located at:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplatesCache\CSharp\Web\1033\WebApplicationProject.zip

Here I am going to change the default contents of the Default.aspx file. Make sure you have taken the backup before modifying the contents of the default template.

Now, let's add a new item to the project. Right click on the project and click on Add and New Item. Select the Web Form and click on the add button. When we add a new item to the solution explorer, say a new webform, we do not see the changes. This is because the item templates are taken from the different template location.

In Web application project, neither do we have inline code model nor do we have an option to preset the master page for the webform. Below is the location for the default template.

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache\CSharp\Web\1033\WebForm.zip

I hope this helps.

 

Technorati Tags: Visual Studio Templates Default templates Visual Studio Default templates Modify VS templates Web Templates Web Templates

Comments