How To Add a License to Code Files
- 2 minutes to read
The Add Copyright Header code provider and the h template allow you to add a copyright comment at the beginning of a source code file.
This comment can contain a file name, company name, author, and a license.
The following example shows how to customize the h template to add a license to a copyright comment.
Choose the CodeRush | Code Templates... item in the CodeRush menu to access the code templates options page.
Select the 1-key | h template.
CodeRush stores the default copyright header as an h template expansion in the template editor. The default copyright header uses the following String Providers:
- «?FileName» — returns the current file's full path.
- «?GetUserFirstName» — returns the "First Name" value from the IDE | User Info options page.
- «?GetUserLastName» — returns the "Last Name" value from the IDE | User Info options page.
- «?GetUserInfo(key)» — returns an arbitrary value from the IDE | User Info options page. You can specify which value to return using the key parameter.
Add a license to the default copyright header. For example, the MIT license:
Click OK to save the changes and close the Templates options page.
Open the IDE | User Info options page and configure the "Company", "First Name", and "Last Name" fields for the default copyright header:
Open a source file and perform one of the following actions:
Run the Add Copyright Header code provider.
Expand the h template on the first line.
Add a License to All Project Files
Open the Editor | C# (Visual Basic) | Code Cleanup options page and choose the Add copyright header rule.
Configure the Add copyright header rule:
Enable "Apply In Action" to allow CodeRush to apply the Add copyright header rule when you call code cleanup.
Enable "Apply on Save" and Apply Code Cleanup when saving a document options to allow CodeRush to apply this rule in code cleanup before a file is saved.
Click OK to save and apply the settings.
- Clean up your project:
- Right-click the project you want to clean in the Solution Explorer.
Select CodeRush Cleanup in the context menu.
or
- Save your project file, if you allowed CodeRush to apply this rule in code cleanup on save.