Creating 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. I.e., 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.
To add a new file to a file template
- Create a new file template or open an existing file template for editing.
- 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.
- 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.
- If yoi 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.
- 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.
- 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', etc. stand for secondary files.
- 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.
- To save the template, choose on the Visual Studio menu or press Ctrl+S.
This feature is supported in the following languages and technologies:
The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.