Darrell Hawley: Home Page

Thursday, July 28, 2005

Enterprise Templates for VS.NET 2003 Professional

I'm currently working on a project that requires a number of very similar project be built. Since I really despise repetitiveness, I looked into creating a creating a project template that would appear in the "New Project" dialog. After a quick Google search, I found a blog entry by Ryan LaNeve that addressed the problem. Because the solution is not a difficult one, it is much more likely that you would use it. Note that my example is specific to C#, though this could just as easily be applied to VB or C++.


  1. First you'll want to create
    a new project that will act as the basis of your template.

  2. Next, edit the
    <Microsoft Visual Studio .NET 2003 installation
    directory>\VC#\CSharpProjects\CSharp.vsdir
    . Copy any one of the lines
    already appearing in the file and then paste it at the bottom. I would recommend
    copying the line that references the project that is the base of the project
    template you are trying to create. The line looks something like the
    following: <*.vsz file name>|<GUID - leave this
    alone>|<Project Name>|<Sort Priority>|<Project
    Description>|<GUID - leave this alone>|<Icon Resource ID -
    leave this alone>| <Flags (probably blank) - leave this alone>
    |<Suggested Base Name>.
    Make changes as necessary.

  3. Now copy one of the *.vsz
    files in the same directory and rename it using the name you entered for the
    first parameter in the step described above.

  4. Open your new *.vsz file
    and change "WIZARD_NAME" parameter to a unique folder name. The line
    you are changing should look like " Param="WIZARD_NAME = <foldername>"
    ". Take note of the foldername.

  5. now go to the
    <Microsoft Visual Studio .NET 2003 installation
    directory>\VC#\VC#Wizards
    directory and copy and paste one of the
    subfolders. Rename it using the foldername you entered in Step 4. Delete all
    files in the Templates\1033 subdirectory except the
    templates.inf file.

  6. Now for the stuff that isnt
    so "cookie-cutter". Locate all of the files in your base class except
    project files and solution files. You would probably be interested in files with
    the following extensions: .cs, .aspx, .asax, etc. This is by no means an
    exhaustive list. Copy them to the Templates\1033 subdirectory located
    in the directory you created in Step5.

  7. Open the templates.inf
    file, remove the current entries and then list all of the files that you copied
    from the base directory in Step 6.

  8. Open up each of the files
    now listed in the templates.inf directory and locate the Namespace. Replace
    it with "[!output SAFE_NAMESPACE_NAME]". Do this for every reference to
    the original Namespace.

  9. If your project template is
    just a minor revision of an existing template, you really don't have to go
    beyond this step. But what if you have added references or pre- and/or
    post-build events? You'll have to copy your original *.csproj file to the
    <Microsoft Visual Studio .NET 2003 installation
    directory>\VC#\VC#Wizards
    directory.

  10. Open your new *.csproj file
    in notepad and take a look. You will probably need to delete a good portion
    of the contents of this file, though this may not be the case. The best way to
    tell you how to edit this is to open up one of the other *.csproj files and try
    to make your file look similar. Remove all that is unnecessary. You will have to
    delete any files referenced in the <Files> section otherwise you
    will get errors. Visual Studio will automically add the files you copied in
    Step6.


Restart Visual Studio and open a new project. Your custom project should appear.

You might also want to check out the following entry by Michael Weinhardt.
Adding Custom VB.NET Project Item Template Wizards to VS.NET by Michael Weinhardt

2 Comments:

  • i got the following email today and thought it worth posting:

    I am facing problem to create a csharp project programmatically for vs.net 2005. The vsz file mentioned by you <Microsoft Visual Studio .NET 2003 installation
    directory>\VC#\CSharpProjects\CSharp.vsdir. These vsz files are missing in vs.net2005 professional edition. I am having a c# project which generates vs.net 2003 solution and project file. Now I want to port it for generating vs.net2005 code but as vsz files are missing ,so exception occurs and system exits abruptly. Can you help me how should I approach to solve this problem.

    Thanks in advance.


    my response:

    I’m not entirely sure since I have not tried to do this in 2005, but If you checked out the <Microsoft Visual Studio .NET 2005 Installation Directory>\Common7\IDE\ProjectTemplates\CSharp\Windows\1033\, I’m guessing you should be able to come up with a solution.

    hope this was useful.

    By Blogger Darrell Hawley, at Tue Aug 01, 06:26:00 PM  

  • First, I'd like to thank you for the post

    Second, I am facing a problem and I think you may help me..
    I am actually just begining to learn about web services since I needed it for my graduation project..
    The problem is that the "ASP.Net Web Services" template doesnt exist in my template pane..
    I am using VS.Net 2005 and ofcourse I cant get started with anything practically because of the missing template..
    So how can I get this template ?

    By Anonymous Anonymous, at Thu Dec 06, 12:41:00 AM  

Post a Comment

<< Home