Add file header to new class/other items automatically on creation in Visual Studio


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

  1. Navigate to the below folder
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\
  2. 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.
  3. Make any more changes as required. Save.
  4. Go back to visual studio to check if it is actually working.
  5. 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.

Add document header for files automatically in Visual Studio


This entry was posted in General and tagged , , , . Bookmark the permalink.

4 Responses to Add file header to new class/other items automatically on creation in Visual Studio

Leave a Reply

Your email address will not be published. Required fields are marked *