Search code examples
resharperlive-templates

Automatically add imports with ReSharper templates


I am writing live templates for ReSharper that rely on types defined in an external namespace.

Is there a way to tell it "Add a using directive if needed", so that I don't have to fix that manually after each use

/* Template expands to */
var $ListName$ = new List<$Type$>()$END$;

/* But sometimes needs to import */
using System.Collections.Generic;

Solution

  • Yes, this is possible.

    Fully qualify your type names, and select "Shorten qualified references".

    Live templates