C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » General »

How to create new project templates for Visual Studio .NET


Posted Date: 03 Apr 2004    Resource Type: Articles    Category: General
Author: N.T.GopalakrishnanMember Level: Gold    
Rating: 1 out of 5Points: 7



As we create standards and customization to our projects, it will always be better if those customizations come as a template, instead of everyone doing the same things again and again. Creating templates also offer an advantage that any changes to it are globally consumed, thus offering consistency in the approach. This document explains the steps that one would have to do in order to create a new Project Template as well as individual project items.

Although this article explains about creating templates for VB.NET, you could easily reproduce this for C# also.

Creating a new Project Template

A new project template is created so that it can be seen under the list of new projects offered by the VS.NET IDE, when you opt for creation of new project. To create a new project template, follow the steps given below:

1. Locate your vb7 folder. Generally, it will be C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO .NET 2003\VB7. This path is the default one, if you have not changed during the installation.
2. Then locate the VBPROJECTS sub-folder under the VB7 folder.
3. Create a new .VSZ file. You can use any editor to create a new .VSZ file.
4. There is a defined way in which you would edit the .VSZ file.

VSWIZARD 6.0
Wizard=VsWizard.VsWizardEngine.7.1
Param="WIZARD_NAME = MVCApplication"
Param="WIZARD_UI = FALSE"
Param="PROJECT_TYPE = VBPROJ"

5. Look for the “WIZARD_NAME”. This is very important. You will use the same name to create a folder under the VBWIZARDS folder (explained later).
6. Save this as “MVCApplication.vsz”.
7. There will be a file called Projects_std.vsdir file. The vsdir files will contain multiple VSZ files. Edit the file using any text editor. At the end of the file, append the following line (you should type the following in one line):

MVCApplication.vsz|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|MVCApplication|85|MVC Application|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|4507| |MVCApplication

8. The above lines are delimited by the ‘|’ symbol. The first one tells the actual VSZ file created by us, the second is the same guid used by the WindowsApplication.vsz, the third is the default name of our project, next is the sort order, then again the same GUID used by the WindowsApplication.vsz. Leave the other numbers and blanks and finally our application name again.
9. Save the projects_std.vsdir file.
10. Locate the VBWIZARDS folder and create a new folder called MVCApplication. This name should be equal to the name you gave in Step 3.
11. Create 2 new sub folders – Scripts and Templates. Again Scripts and Templates should have “1033” as their respective sub-folders.
12. The Scripts -< 1033 directory needs to have a default.js file. You can copy the file from VBWizards -< WindowsApplication -< Scripts -< 1033 folder.
13. Our Templates -< 1033 folder should have the list of files that we would need to give when the user opens our project. It should have a VBPROJ file and may be one Windows Form and Class file. You can copy the Form.vb from the existing “WindowsApplication” folder and Class.vb from the existing “Class” folder and paste it here.
14. Edit the default.js folder to ensure that we have both our Form.vb and Class.vb added. The default.js file that we copied from WindowsApplication folder has the code to copy the “AssemblyInfo.vb” and “Form.vb”. You can follow the same code snippet, that is used to add the AssemblyInfo.vb file, to add our Class file also. Save and close the file.
15. Open the VS.NET IDE and click on “New Project”. You should see the new project created by us, “MVCApplication” been shown in the list.

Creating a new Project Template Item

Project template items are individual items that we would like to have during the course of developing an application. In our example, the MVCApplication project template had one form file and one class file. (You may edit those files under the Templates -< 1033 directory to customize its template). Therefore, during the development, you may need additional “customized” form or class file. You would do this by right clicking on the Project in the Solution explorer, selected Add -< Add New Item… option. This will throw up the Project Items template dialog. This section explains how you can have the same “customized” template items to find a place under the “Local Project Items” in the dialog.

One thing that you have to know before hand is that we need to have individual VSZ files for showing both our Form and Class templates.

1. Locate the VBProjectItems -< Local Project Items folder under the VB7 folder.
2. Create a new folder called MVC, under the Local Project Items folder.
3. Create a new file called MVCProjectItems.vsdir under the MVC folder. You can copy any other vsdir file and paste it here.
4. The file should have two lines (one each for Form and Class) as following. Type each of those in only one line.

..\..\MVCForm.vsz|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|MVCForm|10|MVC Form|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|4527| |MVCForm.vb

..\..\MVCClass.vsz|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|MVCClass|20|MVC Class|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|4510| |MVCClass.vb


5. Go to Local Project Items folder and paste the above-created vsdir file there. But you should edit the file in such a way that it the “..\” does not come twice (Since we are pasting this file one level up). It should look like this:

..\MVCForm.vsz|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|MVCForm|10|MVC Form|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|4527| |MVCForm.vb

..\MVCClass.vsz|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|MVCClass|20|MVC Class|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|4510| |MVCClass.vb

6. Go to VBProjectItems folder and create the two VSZ files – MVCForm.vsz and MVCClass.vsz. These were the two vsz files that were referenced in the above vsdir files.
7. The MVCForm.vsz file should look like this:

VSWIZARD 6.0
Wizard=VsWizard.VsWizardEngine.7.1
Param="WIZARD_NAME = MVCFormWiz"
Param="WIZARD_UI = FALSE"
Param="PROJECT_TYPE = VBPROJ"

8. The MVCClass.vsz file should look like this:

VSWIZARD 6.0
Wizard=VsWizard.VsWizardEngine.7.1
Param="WIZARD_NAME = MVCClassWiz"
Param="WIZARD_UI = FALSE"
Param="PROJECT_TYPE = VBPROJ"

9. Go to VBWizards folder and create two new folders – MVCFormWiz and MVCClassWiz.
10. Create two folders under the MVCFormWiz folder – Scripts and Templates.
11. Both Scripts and Templates folder should have 1033 as its sub folders.
12. Repeat steps 10 and 11 for MVCClassWiz folder also.
13. Ensure that the MVCFormWiz -< Templates -< 1033 has the same WinForm template, which you have in MVCApplication -< Templates -< 1033.
14. Ensure that the MVCClassWiz -< Templates -< 1033 has the same Class template, which you have in MVCApplication -< Templates -< 1033.
15. Open any project using the VS.NET IDE. Go to Solution Explorer and right-click on the project. Select Add -< Add New Item… option.
16. Under the Local Project Items folder you can see two new items – MVCForm and MVCClass.
17. Expand the Local Project Items folder. You should see a new folder called MVC.
18. Select the MVC folder. You should see the same two items – MVCForm and MVCClass.

That’s it, friends!!




Responses

Author: Andrew Chan    05 May 2004Member Level: Bronze   Points : 0
Hi,

Your article is really great. It helps a lot. However, do you have any idea of how to further customized it for the Configuration Properties so that the Debugging could start from external program with a specific working path and command line argument? I traced the specification storage to the vbproj.user file but I don't know if you can put it into VS.NET customization. Any advice will be much appreciated.


Author: N.T.Gopalakrishnan    06 May 2004Member Level: Gold   Points : 0
hi,

First, thanks a lot for your feedback. You can still customize the vbproj file, for any purpose. All you have to do is to go to VBWizards\MVCApplication\Templates\1033 folder, where you will find the .vbproj file. Open the vbproj file as usual so that it opens this empty project in vs.net. Then go to project properties, set the properties you want and save it. The every time you open the project, all these settings will be preserved.


Author: Andrew Chan    06 May 2004Member Level: Bronze   Points : 0
Thanks for the quick reply.

Can you customize the *.vbproj.user file automatically? As far as I have researched, this file seems to come out from no template. My project was an addition to a 3rd party framework and it utilizes an external debugger. If I cannot customize the vbproj.user file to do it automatically, I still need to change the configurations for several items before I could start. Any other thoughts?


Author: N.T.Gopalakrishnan    07 May 2004Member Level: Gold   Points : 0
Yes you can have the "customized" vbproj.user file in the same Templates directory. But because vs.net uses its own vbproj.user file, you have to manually copy the file by adding few lines in the "default.js" file, which is under the \Scripts directory. It should be added before the line "return 0", so that it "replaces" the original .user file with yours.


Author: Chris    02 Jul 2004Member Level: Bronze   Points : 0
Hi, thanks for this very helpfull article

It answers many of my questions, but I'm still missing an info.

It applies to the code itself, I managed to customize the class.vb file to include a custom comments when creating a new .vb file but now I would like to go further and also customize the statement completion feature,

As an example when I create a new class in an existing vb file I would like to see my comments template, or when I insert a try/catch block I would like the auto-completion to fill the catch with my error handling code.

Do you have any idea to achieve this? I'm sorry if it falls out of topic

Many thanks


Author: Thiago Custódio    09 Aug 2004Member Level: Bronze   Points : 0
How create templates for C# projects ? I repeated the steps, but in the default.js the things are many different. Someone can help me ? Thanks


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to convert C# code to Vb.net
Previous Resource: Validating text boxes for alphabetic and numeric inputs
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use