views:

278

answers:

3

When I right click in the Solution of a C# Visual Studio project and select Add... > Class... it creates a class without a public modifier. How do I get Visual Studio (2008) to default the class to a public class?

+5  A: 

Hi there,

You need to modify the file located in C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033. There is a zip file in there called Class.zip, unpack this, edit the file to put in your public keyword then re-pack it (make sure you backup the original).

Mitch Denny
Thanks Mitch. I had to do a bit more, documented here, but you pointed me in the right direction: http://guyellisrocks.com/coding/defaulting-a-class-to-public-from-visual-studio/
Guy
+3  A: 

You need to change the class template, as described here.

It's slightly more involved than just editing a single file (which is what you might expect) but it doesn't sound too bad.

Jon Skeet
Thanks Jon - appreciated.
Guy
+1  A: 

You could either create your own project template, or modify the existing one. All these project files are template-driven, so you can alter them and/or add your own.

Check out these links:

Marc

marc_s