JetBrains Rider 2018.2 Help

Creating a File Template

File templates are used to create one or more new files with predefined code, such as a type declaration, unit test, etc. File templates have no shortcuts, they are identified by their descriptions. See Creating Files from Templates for details.

The body of a file template consists of plain text, which will appear as is, and parameters. The idea is to combine these to maximize efficiency when invoking the template.

To create a new File template

  1. Depending on the language, where the created template will be applied, open the Editor | File Templates | [Language] page of JetBrains Rider settings (Ctrl+Alt+S).

  2. Click New Template ThemedIcon AddLiveTemplate Screen Gray .

  3. Specify template name in the Description field.
  4. Optionally, in the Default file name specify a name that JetBrains Rider suggests when applying the template. You can also tick the File name must be a valid identifier check box to make JetBrains Rider check if the file name specified when applying the template is valid as a type identifier. This option is helpful if your template creates a file for a new type and the type name is initialized from the provided file name with the Current file name without extension macro. You can check the predefined file templates to see how it is implemented.

  5. To change the default scope of the template, click the Availability button. In the dialog that appears, use check boxes to define where the new template can be applied. You can expand some scopes to specify details (e.g. file masks or language versions):

    Templates selecting scope

  6. Create the body of the template by typing or pasting the desired code.
    The template code can contain plain text and variables. As soon as you type a variable (prefixed and suffixed with $), it becomes available in the. Configure all defined variables as described in the Declaring Template variables section.

  7. Configure template formatting options:
    • Select the Reformat check box to make JetBrains Rider automatically reformats the expanded code fragment according to your formatting preferences settings.

    • Select the Shorten qualified references check box to make JetBrains Rider automatically insert namespace import directives or remove qualifiers that become redundant after the template is applied. If this check box is not selected, JetBrains Rider will not insert any namespace import directives.

When you invoke a command to apply a file template, the drop-down list of available templates is shown to you. We call it 'quick access list' or just 'quicklist'. You can edit this list to add your favorite templates there and/or rearrange their order.

To edit the quick access list

  1. Depending on the language, where the created template will be applied, open the Editor | File Templates | [Language] page of JetBrains Rider settings (Ctrl+Alt+S).

  2. Click icons actions lightning svg on the right of the template list.

  3. In the dialog that opens, use arrow controls to configure which templates are in the quicklist as well as their order there.

Last modified: 21 December 2018