Adding File Headers Made Easy

One of the things on my plate at work is a macro for adding a file header and footer to all the source files in a Visual Studio solution. The macro I put together from my own implementation, various web sources, and a colleague at work accomplished the goal at one time–but inconsistently. So I’d been exploring other avenues for getting this done when Scott Garland told me about the File Header Text feature of ReSharper. You simply put in the text you want to appear at the top of your source file, add a new Code Cleanup profile, check the Use File Header Text option, then run the new profile on your solution.

The result: if the filename ends in “.cs”, ReSharper will add the value in File Header Text as a comment to the top of the file. It’s even clever enough not to add duplicate text if a file already contains it in its header. So if you need to add copyright notices or any other text to the top of your source code files, and you use ReSharper, you’ve already got what you need.