Speed up with Project Templates
page 2 of 4
by Ameet Phadnis
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 31248/ 74

Folders required for Project Templates

VBProjects Folder

For the New Project Dialog Box, Visual Studio.NET needs to know from where it needs to pull all the template names for the Visual Basic language. Visual Studio .NET refers to the vsdir file under vbProjects folder. Typical vsdir file has entries like this -

WebApplication.vsz|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|#3008|40|#3009|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|4504| 1|WebApplication1|Web

The above is a typical entry for Web Application. The entry is delimited with | character. The first column defines which vsz file Visual Studio needs to look at to get information on Wizard. The value 4504 in column 7 is the image Visual Studio takes to display in the templates. The 8th column actually represents that this is a Web Application. (I have not seen any documentation by Microsoft which explains this but I did try it and it worked)In case of Web Application, WebApplication1 is the default project name given when you are creating a new Project. For your specific template, you can create your own vsdir file or just create an entry in existing vsdir file.

In short, vdir file is an optional file. Visual Studio.NET new project templates looks at the vsdir file to find out about project templates for the language.

VSZ files actually points to the right template folder under VBWizards folder. vsz file has the information where it needs to go and get the templates for the project. VSZ files represents the item that appears in the add item dialog or project dialog boxes. Typical vsz file looks like -

VSWIZARD 6.0

Wizard=VsWizard.VsWizardEngine.7.1

Param="WIZARD_NAME = WebApplication"

Param="WIZARD_UI = FALSE"

Param="PROJECT_TYPE = VBPROJ"

In short, Visual Studio new project dialog box looks at the vsdir files and the vsdir file looks at vsz files to get information on templates. The vsz and vsdir files are located in the vbProjects folder.

VBWizards

VBWizards folder is where all the information regarding the templates is stored. As in previous section we saw that vsz files direct Visual Studio .NET New project dialog box to the templates folder in VBWizards folder. The project templates folder has two folders namely Scripts and Templates. Both these folders have 1033 folder.

Scripts folder

The scripts folder contains the default.js file. Each project template needs to have this default.js file. The default.js file has the onfinish function which gets executed as soon as the user clicks Finish or Open in the New Project dialog box. I won't explain the complete onfinish function over here. But I would like to highlight some of the major code for this article. Lets look at the following code in default.js -

var strProjectName = wizard.FindSymbol("PROJECT_NAME");

        var strProjectPath = wizard.FindSymbol("PROJECT_PATH");

        var strTemplatePath = wizard.FindSymbol("TEMPLATES_PATH");

The above code gets information on what the project name was entered by the user. The project path is where the user wants to store this project and the template path is from where the project needs to get the default files for this kind of template.

The following code creates the Visual Basic Project in the Solution.

   var project = CreateVSProject(strProjectName, ".vbproj", strProjectPath, strTemplateFile);

The above code will get the user entered project name and use the template project file to create the new project in the solution. Now the question remains on how do we add files to this project. In the same onfinish event we have functions called AddFileToVSProject which allows us to add the template files to our project. For example, to add Webform.aspx page to our project and name it as WebForm1.aspx. The following code is used -

strTemplateFile = strTemplatePath + "\\WebForm.aspx";

item=AddFileToVSProject("WebForm1.aspx", project, project.ProjectItems, strTemplateFile, false);

The above code gets the template file WebForm.aspx for Web Application and while adding it renames it to WebForm1.aspx. If you are creating an Web Application then the WebForm1.aspx page is marked as start up page. The following code helps us in marking a page as start up page.

var configs = new Enumerator(project.ConfigurationManager);

            for(;!configs.atEnd();configs.moveNext())

            {

                configs.item().Properties("StartPage").Value = "WebForm1.aspx";

            }

To summarize, the script folder contains a javascript file called default.js. This default.js file contains onfinish function which is ran when the user clicks on Open on the New Project Dialog box. This onfinish function creates the project and if there are any templates to be added to the project then it adds it for you. It also allows you to rename the objects and set a page as startup page for the project.

Templates folder

Templates folder is where most of your templates will be stored. The templates can be pages, webuser controls, classes or anything you need as startup for any of your projects. In case of Web Application, the following files are in the templates folder -

1. WebForm.aspx - which gets renamed to WebForm1.aspx.
2. Global.asax - This is copied as it is without renaming it.
3. Web.Config - This is copied as it is without renaming the file.
4. Style.css - This is copied as it is without renaming the file.
5. WebApplication.vbproj - This file is used as template but renamed it to the user entered project name.
6. AssemblyInfo.vb - This file is copied as it is.

In this section, I explained how the folders play a role in your project templates. The next section explains some of the keywords that might come in use while building your own Web Project Template.


View Entire Article

User Comments

Title: very good   
Name: Richard
Date: 2007-01-16 7:59:44 AM
Comment:
very good ,thank u
Title: Speed up with Project Templates   
Name: Prasad
Date: 2004-08-10 8:08:58 AM
Comment:
Excellent article. It saves development time.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 6:56:27 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search