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.
NoteBy 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.
- Choose ReSharper | Options | Code Editing | C# | Namespace Imports (for C# settings) or ReSharper | Options | Code Editing | Visual Basic .NET | Namespace Imports (for VB.NET settings).
- Modify settings in these tabs as required to comply with your coding practices/standards.
- Choose Code Editing | Code Cleanup in the ReSharper Options dialog box.
- 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.
- Click OK to save the new profile and close the ReSharper Options dialog box.
- Open the Code Cleanup dialog box from the text editor or Solution Explorer as described in
Running Code Cleanup.
- When the Code Cleanup dialog box opens, select the newly created profile in the Available Profiles area.
- Click Run to perform Code Cleanup. ReSharper will delete all redundant namespace import directives.