JetBrains Rider 2024.3 Help

Create a file template

File templates are used to create one or more new files with predefined code, such as a type declaration, unit test, and so on. File templates have no shortcuts, they are identified by their descriptions. For more information, refer to Create files from templates.

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.

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).png.

  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 checkbox to make JetBrains Rider check if the filename 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 filename 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 checkboxes to define where the new template can be applied. You can expand some scopes to specify details (for example, file masks or language versions).

    If the template uses classes and methods from non-system assemblies, you can make the template available only in projects that reference these assemblies — in the Global category, select References and specify assembly names without the .dll extension:

    JetBrains Rider: Selecting a scope for the template
  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 Edit variables dialog . Configure all defined variables as described in the Declare template variables section.

  7. Configure template formatting options:

    • Select the Reformat checkbox to make JetBrains Rider automatically reformats the expanded code fragment according to your formatting preferences.

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

  8. Click Save in the Settings dialog to apply the modifications and let JetBrains Rider choose where to save them, or save the modifications to a specific settings layer by choosing this layer from the Save selector. For more information, see layer-based settings.

When you invoke a command to apply a file template, the 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.

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

  4. Click Save in the Settings dialog to apply the modifications and let JetBrains Rider choose where to save them, or save the modifications to a specific settings layer by choosing this layer from the Save selector. For more information, see layer-based settings.

Last modified: 11 February 2024