Monday, July 18, 2011

Class Template is missing in Visual Studio

After playing around with Stylecop for a while, I decided to remove it from my system. So I just uninstalled it and everything seemed fine…until I tried to create a new class in Visual Studio. The class template was gone! I discovered that Stylecop replaces the default class template with it’s own one. However it doesn’t put the old one back in place after removing Stylecop.

So how do you get this template back?

I noticed inside the Visual Studio template folder(C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033) that the class template was still there but renamed. I changed it back to the original name and thought that the job was done. But I still had no class template available.

It took me some time to figure it out but in the end, I solved it by executing the following extra actions:

  • Close all Visual Studio instances.
  • Open a Visual Studio Command prompt.
  • Execute “devenv /InstallVSTemplates”. This command registers project or item templates that are located in <Visual Studio installation path>\Common7\IDE\ProjectTemplates\ or<Visual Studio installation path>\Common7\IDE\ItemTemplates\ so that they can be accessed through the New Project and Add New Item dialog boxes.
  • Execute “devenv /Setup”. This command forces Visual Studio to merge the resource metadata that describes menus, toolbars, and command groups from all VSPackages available.

Only after executing all these steps, my class template was back!

No comments: