Add file header

This code generation applies to:

  • C#

  • Visual Basic

What: Add file headers to existing files, projects, and solutions using an EditorConfig.

When: You want to easily add a file header to files, projects, and solutions.

Why: Your team requires you to include a file header for copyright purposes.

How-to

  1. Add an EditorConfig to a project or solution if you do not already have one.

  2. Add the following rule to your EditorConfig file: file_header_template.

  3. Set the value of the rule to equal the header text you would like applied.

    EditorConfig file header rule

Note

You cannot have explicit multilines in an EditorConfig and will need to use the Unix newline character to insert new lines.

  1. Place your caret on the first line of any C# or Visual Basic file.

  2. Press Ctrl+. to trigger the Quick Actions and Refactorings menu.

  3. Select Add file header.

    EditorConfig file header rule

  4. To apply the file header to an entire project or solution, select Project or Solution under the Fix all occurrences in: option.

  5. The Fix all occurrences dialog will open where you can preview the changes.

    Fix all occurrences dialog

  6. Select Apply to apply the changes.

See also