Visual Studio 2008 templates compliant with Microsoft StyleCop

Motivation

Since Microsoft launched StyleCop, we are running this tool in all Southworks' projects. From our Engineering Excellence department we’re promoting the use of this tool because it give us source code consistency and homogeneity we want for developers and customers who read the code.

If you're using this tool, you surely be realized that some Visual Studio templates are not compliant with some of the StyleCop rules, like using directives inside the namespaces, regions, one class for each file, among others. This is quite annoying when you’re coding because each class, interface or test you add to your project has to be stylized to meet that rules.

Project templates like ASP.Net Web MVC Application (Preview 5) have an amount of ~120 warning even avoiding the documentation rules.

The purpose of this post is to give you a workaround to avoid this unnecessary work.

Context

The way that Visual Studio provides these templates is by using a series of compressed zip files, with the base source code inside.

There are two folders inside the %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\” with these templates, one for the items (classes, interfaces, tests, etc.) and one for projects (Class Library, Console Application, MVC Web Application, etc.).

Workaround

The workaround is pretty much straightforward, all you have to do is:

  1. Extract the default Visual Studio template files
  2. Modify them to be compliant
  3. Compress it again
  4. and overwrite the original files

What I did this weekend, is make the work for you for the most used files and projects for me including the Microsoft ASP.Net MVC preview 5 project template :). So below you’ll find a table with the zip files to download and the folder location where you will overwrite them.

Once you have copied the files, ensure you’ve all you Visual Studio instances closed and run as administrator from the console the following command to refresh Visual Studio's template cache:

“%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\devenv.com" /setup"

Template Files

(*) rootPath = "%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\"

template path template file

(*)\ItemTemplates\CSharp\Web\MVC\1033

(*)\ItemTemplates\CSharp\1033

(*)\ItemTemplates\CSharp\Code\1033

(*)\ProjectTemplates\CSharp\Web\1033

(*)\ProjectTemplates\CSharp\Test\1033

You can also download all templates in a single .zip file: AllTemplates.zip

Published: September 01 2008

  • category:
blog comments powered by Disqus