As many of you already know, I’m working on a project based on the .NET Framework 2.0 beta and Visual Studio 2005 beta. Due to client requirements we analyzed both .NET Framework 1.1 (current and stable version) and the new 2.0 version (beta but quite stable) and decided to go with the second one due to the gain in productivity, performance and flexibility.
As the project is very long in time, probably (more like maybe) these products will hit the final versions before we even arrive at the middle of our work. I say probably/maybe because unfortunately Microsoft is always pushing away the release dates for these products, so we don’t know for sure when it will hit the market.
Visual Studio 2005 has some very interesting things. One of those is actually a re-design of a very bad designed feature in Visual Studio .NET 2003: Code templates.
When you work on enterprise development with large teams you always want to enforce certain basics on coding style and usually you have the plumbing code that must always be in certain classes. This can be “using” directives, base classes, interface implementation or simply comments and coding style.
The most natural way to enforce that would be to create your basic code skeletons containing all the stuff you want to enforce and set it as a template, so that developers can just create a new instance of those templates and get everything well formatted and configured for them.
Well, in Visual Studio .NET 2003 you do can create your own templates, but it is a hassle, very badly explained and cumbersome. You have to create your template code and put that in an specific directory, but then to have Visual Studio using them, you have to create a certain directory structure, create a “.vsz” file containing directives to the “Create New Item” wizard, and finally edit one of the multiple “.vsdir” files to glue things together and have the IDE showing your templates in the new items dialog box.
In Visual Studio 2005 it has completely changed: Now you almost don’t have “.vsz” or “.vsdir” files any more and creating most of the templates is very straightforward. Actually now a template is composed by two files zipped together and the zip file goes to a item templates folder. The same is true for projects, but you have obviously to provide some more files.
The two item template files are the “.cs”, “.vb” or “.whatever” file you want to create. In this file you use a simple syntax to tell the item creation wizard where to put class and namespace names and stuff.
Then you have another XML file with the extension “.vstemplate” that contains information like item name that should be presented in the item creation dialog, item icon, references you need for that item and all other information for the IDE to create new items based on that template.
These templates can sit on the Visual Studio folder (if you’re doing an enterprise deployment of such templates) or can sit in your own Visual Studio folder under your “My Documents” folder.
It is very good, I have tried it and it works effectively. We are actually deploying templates for VS 2005 for our project and it is smooth and goes fine.
There is one small problem, though: If you try to follow this method for Web app items like Web Forms, User Controls, master pages and etc you will not get anything close the expected.
To create web item templates you have to dig a bit in the directory structure of VS 2005. You will quickly discover that the web templates haven’t been updated to use the new creation method, but they still use the VS .NET 2003 procedure with a slightly different directory structure.
I’m sure, though, that Microsoft will update this at some point and I believe it can be before the official beta 2 comes out. The version of VS 2005 I’m using, actually, is a bit outdated as you have two latest versions available: The first one is the VS 2005 Professional, which has got its latest release in November 2004. The other version is the VS 2005 for the Team System, which is more complete but not updated as the first one. The latest release for that one is from December 2004.
Wednesday, February 16, 2005
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment