This post shows how we can make little changes to the Class template in visual studio so that we can add a file header to a newly created class. It’s generally a good practice to add a file header to any class/file in a solution but it’s equally a pain when we have to copy-paste a file header from a different file and remember to change the name at the top. Instead you can just follow the below steps to make Visual Studio add it automatically for you with the right filename when you create a new class.
Note: I’ve done this for Visual Studio 2015. But it is pretty much the same for other versions
- Navigate to the below folder
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\
- Open the Class.cs file in notepad or any editor you find comfortable. Edit it as shown below. Basically just add the file header you wish to add to every class. But edit the filename to $safeitemrootname$.cs. This will ensure that the name of the file you’ve provided is replaced here.
- Make any more changes as required. Save.
- Go back to visual studio to check if it is actually working.
- Modify other templates like for Interface or any other file type if required. Note : you might want to check the folders at the 1033 level in the above path.
Hope this helps!
The below post by Abhijit Jana shows very clearly how the same can be achieved with more controls using Macros. Do have a look.