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 -
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 -
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 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.
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);
configs.item().Properties("StartPage").Value = "WebForm1.aspx";
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.