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 ReSharper Tips&Tricks and tagged , . Bookmark the permalink.

5 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.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>