ReSharper 2024.3 Help

Create multi-file templates

A file template can create more than one file when you apply the template. This may be helpful when related data is saved in different files.

Here are a few things you need to know about multi-file templates:

  • A file template always include one main file, and, optionally, any number of secondary files. So as soon as you add a secondary file to any file template you get a multi-file template.

  • When adding a secondary file, you can reference any existing file template (Add file from existing template option). Note that if the referenced template has multiple files too, then only the main file of the referenced template will be added when you apply the template.

  • The set of parameters spans all files of a multi-file template. That is, if you use the same parameter $PARAM$ in several files of a multi-file template, it will have the same value in all related files when the template is applied.

  • If a multi-file templates has editable parameters, the Hot spot session, which deploys when you apply this template, will guide you through all created files where the user input is required.

Add a new file to a file template

  1. Create a new file template or open an existing file template for editing.

  2. At the bottom of the Template editor, click Add new file or Add file from existing template. A new section will be added below the body of the main file.

  3. By default, the new secondary file is added in the same project as the main file. If you want it to be added in a different project, specify the name of this project in the Project field. Note that if the specified project does not exist in a solution where the template is applied, the secondary file will not be added.

  4. If you want the secondary file to be added in a different folder, specify it in the Folder field. Use the backslash for folder hierarchy. Note that if some project is specified, the new folder path will be relative to this project, otherwise it will be relative to the main template file.

  5. Specify a name for the secondary file. $NAME$ will be replaced with the name of the main file without extension. Note that unlike with the main file, you will not be prompted for names of secondary files.

  6. If you added the secondary file with Add new file, provide the body for it. You can use parameters, which share their values within all files of the template. If some parameter is used in several files and you are going to keep it editable, select the editable occurrence in the Parameters area to the right; this occurrence will be editable in the Hot spot session when the user applies the template. In the selector, the occurrences have numbers prefixed with letters: 'M' stands for the main file, 'S0', 'S1', and so on. stand for secondary files.

  7. If you used Add file from existing template to add a new file, instead of the file body, you will see the list of parameters of existing template. If necessary, you can map these parameters to the parameters of the current template.

  8. To save the template, choose File | Save Selected Items on the Visual Studio menu or press Ctrl+S.

This feature is supported in the following languages and technologies:

Language: C#

Language: VB.NET

Language: C++

Language: HTML

Language: ASP.NET

Language: Razor

Language: JavaScript

Language: TypeScript

Language: CSS

Language: XML

Language: XAML

Language: Resx

Language: Build Scripts

Language: Protobuf

Language: JSON

Feature is available in C#

Feature is available in Visual Basic

Feature is available in C++

Feature is available in HTML

Feature is available in ASP.NET

Feature is available in Razor

Feature is not available in JavaScript

Feature is not available in TypeScript

Feature is not available in CSS

Feature is not available in XML

Feature is available in XAML

Feature is not available in Resource files

Feature is not available in build script files

Feature is not available in Protobuf

Feature is not available in JSON

The instructions and examples given here address the use of the feature in C#. For more information about other languages, refer to corresponding topics in the ReSharper by language section.

Last modified: 11 February 2024