ReSharper Web Help

Any previously imported namespace can become redundant in your code. Without ReSharper, you have to stop what you are doing, scroll to the top of every file, find unused namespace import directives, and remove them. ReSharper makes life a lot easier by automatically removing unused namespace import directives from your file, project or solution, at any time. This can be done either with a quick-fix or using Code Cleanup.

 Note

By default, ReSharper does not optimize using directives in auto-generated code (for example, in Windows Form Designer-generated code). If necessary, you can modify the list of files and regions that ReSharper skips in the Code Inspection | Generated Code page of ReSharper options.

To optimize namespace import directives using Code Cleanup
  1. Choose ReSharper | Options in the main menu.
  2. Open Code Editing | C# | Namespace Imports (for C# settings) or Code Editing | Visual Basic .NET | Namespace Imports (for VB.NET settings).
  3. Modify settings in these pages as required to comply with your coding practices/standards.
  4. Open Code Editing | Code Cleanup options page.
  5. Create a new profile as described in Creating Custom Profiles. In the Selected profile settings for the new profile:
    • Select Optimize 'using' directives.
    • Alternatively, to embrace unused using directives in a region, select Embrace 'using' directives in region and specify the name of the region in the Region name field.
  6. Click Save to apply the modifications and let ReSharper choose the settings layer, or choose a particular settings layer in the Save To drop-down list. To learn more about saving ReSharper settings, see JetBrains .NET Tools Blog: Save or Save To in ReSharper Options.
  7. Choose ReSharper | Tools | Cleanup Code in the menu to open the Code Cleanup dialog box for the current file or for a solution node (see Running Code Cleanup for details), and then select the newly created profile in the Available Profiles area.
  8. Click Run to perform Code Cleanup. ReSharper will delete all redundant namespace import directives in the current file of in the selected solution node.

See Also

Concepts

Procedures