Everyone has their own coding style. There isn’t a specific one that’s better than the rest. Personally, I like what the guys at IDesign: IDesign C# Coding Standard, which is a development guideline and best practices for C# development.
I also like customizing the file templates within Visual Studio so when I create a new file, its setup the way I want it. For example, I am a region-a-holic… I stick everything in this buggers. I also don’t use tabs for indentation… always use spaces (EVERY editor, VS, Notepad, Notepad2, Nodepad++, etc. interprets spaces the same way, not the same with fonts). The image to the right shows what one of my empty class files look like.
It was a royal PITA when you wanted to move your code templates and settings from one machine to another in Visual Studio 2003. There were registry entries, files embedded within your profile, and files embedded within the VS program directory.
Visual Studio 2005 addressed this problem and made it a lot easier to move your settings around with the import/export wizard. Now all your settings are persisted in a single file you can move around. All the file templates are also in one place (except for your personal additions). One of the first things I did was update my settings in the IDE and update all the file templates to reflect my preferences. It’s pretty self explanatory and well documented how to move your settings around so I won’t cover that.
You’ll find your file templates here: C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates. This directory contains a bunch of ZIPs. Each ZIP contains all the files necessary for each file type. For example, the WebForm.zip file contains the ASPX, a codebehind, and the designer codebehind file (partial class).
I’ve linked the contents of my ItemTemplate directory for reference. Once you’ve made your changes to your own ItemTemplate directory, you’ll need to update the ItemTemplateCache directory, but that’s easier as VS has a command line switch to extract all your ItemTemplate files into the ItemTemplateCache.
Run the following command from a VS command line: devenv.exe /InstallVsTemplates
Thanks to Scott Guthrie & Tim McBride @ MSFT for verifying a few questions WRT to the Web Application Project. When you install the Web Application Project, it overwrites a bunch of files (ItemTemplates[language]\1033*.zip) in the ItemTemplate directory so you may have to go in and update your templates.comments powered by Disqus