Classes are internal by default. Class members, including nested classes, can be public, protected internal, protected, internal, private, or private protected. Members are private by default.
To add a class in a Visual Studio C++ project, in Solution Explorer, right-click the project, choose Add, and then choose Class. This command opens the Add Class dialog box.
Choose File > New > Project from the menu bar. Select the template that you want to update and continue through the steps to create the new project. Modify the project in Visual Studio. For example, change the output type or add a new file to the project.
In VS2012 it's as easy as going to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class
and editing the Class.cs file.
No need to unzip or rebuild cache. A very positive change if you ask me.
VS2015: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class
VS2017(RC): C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class
VS2017(Professional): C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class
VS2019 (Enterprise): C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
VS2019 (Professional): C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
Outdated
VS2019 (Preview): C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
You need to modify the file located in C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033
.
Visual Studio 2010 (10.0) and below: 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).
After this, make sure VS rebuilds it's cache (which is just the zipfiles unzipped into directories in C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache
) by opening a Visual Studio command shell and execute the following command:
devenv /installvstemplates
Visual Studio 2012 (11.0) and up: See the answer by @JochemKempe, as it's much easier to change this now, just by editing a single file (no unzipping or rezipping).
UPDATE: Don't forget to open your preferred text editor with admin privileges before you do any edit.
To create a Public class by default for Visual Studio 2012:
Edit this file:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
To look like this:
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $rootnamespace$
{
public class $safeitemrootname$
{
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With