Sunday, February 26, 2012

Getting to know Visual Studio Template Replacement Parameters

If you have been working with creating your own custom Project or Item Templates in Visual Studio, you may find many of the replacement parameters confusing (at best).

There are numerous replacement parameters available, but the most common ones that you will use while creating your Project and Item Templates are listed below:
safeitemrootname Most often used with files that may span several files such as a WCF Servce
safeprojectname Most often used in Web Applications
rootnamespace Most often used in Class Library projects for class files
classname  Used to dynamically create the class name in any class file including code behind files

There are actually many more available to use across all of your various projects as can be found documented here:  http://msdn.microsoft.com/en-us/library/eehb4faa.aspx

Interestingly enough, however, if you extract some of the Project and Item Templates that are included as part of the Visual Studio 2010 installation, you will encounter many more which are completely undocumented such as the use of codebesiderootname and codebesideclassname or even masterpage or pagecontent.

As you dig further into creating your own Item and Project Templates, the best source of reference for developing these will ultimately be what Microsoft has done itself in the creation of various templates used within Visual Studio.

The great thing about creating your own Item and Project Templates is that these can easily be shared with a development team to encourage re-usability and standardization of development throughout projects in your organization.  

Rather than have individual developers create brand new Visual Studio projects that need to be heavily customized, you can now export these templates and share them with your development staff so as to save them from all of this customization effort.  If you also participate in periodic code reviews, you can probably imagine how much nicer it will be to perform these code reviews when every developer is using the same set of templates to develop their projects and their code!



No comments:

Post a Comment