After some Googling I found this: Use a Visual Studio Macro to Insert Copyright Headers into Source Files. It looked promising:
// <copyright file="Sample.cs" company="My Company Name">
// Copyright (c) 2012 All Rights Reserved
// </copyright>
// <author>Leniel Macaferi</author>
// <date>08/30/2012 11:39:58 AM </date>
// <summary>Class representing a Sample entity</summary>
When I tried Tools -> Macros menu option it wasn’t there anymore in VS 2012. Here’s the proof: Macros in Visual Studio 11 Developer Preview. They just dropped this functionality. 🙁
So, I’m just curious to know which option I could use to add the copyright info to all existing source code files in my solution using Visual Studio 2012. Is there any standard way of doing this, using a template file (something related to T4 templates) or a PowerShell script? I could write some code to iterate over the files with .cs extension and add the copyright info but that is not what I’m after. I’d like to know about some tool to automate this process.
You could create a new snippet and just type cp + double tab to insert the notice where you want (needless to say you can change the keyword to whatever you want).
The only problem with it is, from what I’m aware, snippets do not support time functions, so getting the current time for your date line seems impossible with this technique. A not so good workaround for this is to make the time fields editable (similar to how the mbox snippet works) and just insert the time manually.
Here’s an example on how a snippet looks. The bellow snippet will get the class name automatically and insert the copyright notice in the place where you type ‘copyright’ and double tab.
Method 1
Method 2
Also, here’s an example of a program you can make to do that for you.
Some error catching will be required of course. But this should give you the general idea how to construct an UI around it an add the files you will want to process.
Method 3
It’s also possible to change the template for your classes that can be usually be found under:
Sometimes editing ItemTemplatesCache is also necessary to display the results.
Here’s an example template based on your question: