File Header Macros in ReSharper 6

Previous posts introducing ReSharper 6:

Sometime ago I wrote about Automating File Header Information, showing how to insert license information and other data in project files. One of the shortcomings ReSharper had however was the inability to support macros. Something as simple as inserting the current year or filename required the support of StyleCop for ReSharper. ReSharper 6 now support macros allowing file headers to contain varying information:


For instance, in the previous license header, the Copyright years are fixed to 2010 – 2011. It also has no information relevant to the actual project. We could of course hardcode the name of the project in there but since this setting is not solution-specific, it would be of little use. Other data such a filenames however would be impossible to do.

With ReSharper 6 we simply remove the hardcoded values and replace them with macros. We can either type them in or click on the corresponding macro, which will insert it at current cursor position:


With this change in place, next time we run a code-cleanup and have the Update File Header option activated, we will get up to date and project/file specific header information inserted. Next feature request: Custom Macros!

This entry was posted in How-To's and tagged , . Bookmark the permalink.

7 Responses to File Header Macros in ReSharper 6

  1. Jeremy says:

    Unfortunately, enabling file header addition/update seems to cause R# to always modify the file during clean-up, even if it has not materially changed the contents, and this is a step backwards from pre-6 versions of R# which would leave the file alone if clean-up would not change anything. It is a relatively minor issue, but I do hope that this gets addressed in a patch, as it removes the previous ability to instantly know if a clean-up operation has changed the file or not.

  2. Hadi Hariri says:


    Could you please log it with a test case to reproduce in ?


  3. tim says:

    $USER_NAME$ is always empty for me, though $USER_LOGIN$ is not. How do I set $USER_NAME$?

  4. name says:

    The same for me. Why $USER_NAME$ is empty? How can it be set?

    • Matt Ellis says:

      The $USER_NAME$ field maps to the display name of the current user. Under the covers it calls Win32’s GetUserNameEx method, passing in EXTENDED_NAME_FORMAT.NameDisplay. If your account doesn’t have a display name set, it will display an empty string. Setting the display name depends on the type of account you have – a local Windows account can be set on the local machine, if you’re on a domain, I suspect it will have to be changed in Active Directory.

      If you get an empty string for $USER_NAME$, you might want to use $USER_LOGIN$ instead. This shows the user’s login name, rather than the display name.

  5. Mark Kamoski says:

    It would be nice if this had source control macros that linked to TFS, if TFS supports that. Then it could show (as SourceSafe used to do) things like $last_checked_in$ and so on. Just an idea.

  6. Mark Kamoski says:

    Dear ReSharper — Here is another comment about “Code Cleanup” in general. During the Cleanup, ReSharper 9.1 pops up a dialog for me “ReSharper Ultimate is about to open N files to make undo operation available. Opening so many file may cause severe performance penalty. Open anyway?”. This is OK but needs to be fixed a bit. (1). First, this should be changed to make the dialog absolutely-top-most globally relative to all open windows on the box. Rather this window, in my experience, is always getting buried behind and under other windows that are open, while at the same time the top-most window is the ReSharper “cleanup processing” information box. So it looks like ReSharper is still working but ReSharper is actually waiting for an enduser response to a window that is behind other windows and not visible to the enduser. This is not just a problem with ReSharper– this same problem is in SO many install-programs and uninstall-programs and processing-programs. I cannot believe this is not solved globally for all programs, to make it work, but this problem keeps happening even in modern (best of the art) programs like ReSharper. Be a hero and a leader, ReSharper, and be the first to fix this. (2) Second, there should be an option do “do not show this again” or a setting to “do not show warning prompt” so this nag does not happen OR at the very least this “ReSharper Ultimate is about to open” dialog question should be shown at the very start of the cleanup operation, not 1/2 way through it, so an enduser can answer all prompt questions 1st and then go get a cup of coffee while the program does the grunt work. This “ask all questions first” approach is yet another thing that a lot of programs miss so here is again another opportunity for you, ReSharper, to be a hero and a leader and fix what others cannot. Etc. Regardless, ReSharper is a GREAT app in so many ways so thank you for that. Thanks. — Mark Kamoski

Leave a Reply

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