Importing / Exporting Templates and Patterns in ReSharper 6.1
One of the changes introduced with the new settings in ReSharper 6.1 is how importing and exporting of templates and custom patterns are done (Custom Patterns were previously known as Structural Search and Replace). As part of the unification of settings, Templates and Patterns now fall under the same modus-operandi when it comes to importing and exporting as other settings do. This is very similar to how our IDEA based IDE’s such as IntelliJ, WebStorm et al. work. However, certain legacy functionality is also available depending on what needs to be done.
The de-facto choice
Be it Templates or Patterns, when you want to import or export them, the recommended approach is to use the Manage Options dialog
To export, we merely select Export to File. ReSharper prompts us with a dialog box of what we would like to export:
At this point we can select whether we want Live Templates, Patterns (StructuralSearch*) or both. It is important to note that if you do not have any user defined templates and/or patterns, then these options are not available, i.e., you would not see the LiveTemplates / StructuralSearch checkboxes.
The exported file format is only compatible with ReSharper 6.1 and higher (.DotSettings file).
When it comes to importing templates and patterns, if these are in .DotSettings format, then it is merely about adding another layer. We select the file to import, and are prompted on what settings we’d like imported:
The benefit of this approach is not only that it keeps all settings centralized, but it also allows us to mount and un-mount related templates.
* StructuralSearch comes from the old name giving to Custom Patterns which was Structural Search and Replace
Exporting Individual Templates
One option that is currently not available using the Manage Options dialog when dealing with the export of templates is to selectively choose which ones we’d like exported. If we want to only export specific templates, we need to use the Template Explorer (previously named Live Templates)
We can then select individual templates and choose the Export button. This is basically the old behavior prior to ReSharper 6.1. The difference however is that the file exported is in the new .DotSettings format. In this regard, there is no difference between this approach and the previous Manage Options one.
Dealing with legacy templates and patterns formats
The Templates Explorer window also has an option to import Templates
Although this allows the newer DotSettings file format, we usually should only use this when trying to import legacy templates (from version 6.0 and lower).
When it comes to Patterns, when trying to import older ones, we can use the Import from R# v6.0- button on the Custom Patterns options page
With the new settings we’ve hopefully made sharing of Patterns and Templates a little easier. There are still improvements to make but any/all feedback or changes you’d like to see are welcome. Please log them in our issue tracker so that they can be managed better.
Subscribe to Blog updates
Thanks, we've got you!