File Header Macros in ReSharper 6

July 25th, 2011 by Hadi Hariri

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:

SNAGHTML13afe47c

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:

image

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!

Tags: ,

2 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:

    @Jeremy

    Could you please log it with a test case to reproduce in http://youtrack.jetbrains.net/issues/RSRP ?

    Thanks

Leave a Reply