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 doesn't optimize using directives in auto-generated code regions (for example, in Windows Form Designer-generated code). You can modify the list of regions that ReSharper skips in ReSharper | Options | Code Inspection | Generated Code.
To optimize namespace import directives using Code Cleanup
  1. Choose ReSharper | Options | Languages | C# | Namespace Imports (for C# settings) or ReSharper | Options | Languages | Visual Basic .NET | Namespace Imports (for VB.NET settings).
  2. Modify settings in these tabs as required to comply with your coding practices/standards.
  3. Choose Tools | Code Cleanup in the ReSharper Options dialog box.
  4. Create a new profile as described in Creating Custom Profiles . In the Selected profile settings for the new profile:
    • Select Optimize 'using' directives.
    • Optionally, select Embrace 'using' directives with region and specify the name of the region in the Region name field.
  5. Click OK to save the new profile and close the ReSharper Options dialog box.
  6. Open the Code Cleanup dialog box from the text editor or Solution Explorer as described in Running Code Cleanup .
  7. When the Code Cleanup dialog box opens, 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.

See Also

Procedures