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.
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.
- Choose ReSharper | Options in the main menu.
- Open Code Editing | C# | Namespace Imports (for C# settings) or Code Editing | Visual Basic .NET | Namespace Imports (for VB.NET settings).
- Modify settings in these pages as required to comply with your coding practices/standards.
- Open Code Editing | Code Cleanup options page.
Create a new profile as described in
Creating Custom Profiles.
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.
- 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.
- 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.
- Click Run to perform Code Cleanup. ReSharper will delete all redundant namespace import directives in the current file of in the selected solution node.