Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Remove unnecessary usings" not working in Visual Studio 2015

I have a solution with a few projects. Remove unnecessary usings is working in all projects except for one.

Why does the Remove unnecessary usings command not work in some projects?

Edit - As you can see in the Before image there is no Remove unnecessary usings command and if you try to right-click in the file, then Organize usings > Remove unnecessary usings does nothing. After setting the project build warning level to 4 the Remove unnecessary usings command appears and works.

Before:

Before

After:

After

like image 464
david.s Avatar asked Sep 21 '15 14:09

david.s


People also ask

How do I delete all unnecessary Usings in Visual Studio?

First is putting your cursor on one of the grayed out lines and clicking the light bulb, then clicking Remove Unnecessary Usings. (NOTE: The shortcut key for this is CTRL-.) When the action is executed the references will be cleaned up.


1 Answers

Needing to set the Warning Level to 4 for code analyzers to fire is a Roslyn known issue.

Additionally, check your projects' Code Analysis rules (project properties > Code Analysis > Open). We had CS8019 and IDE0005 disabled, which prevents the code fix from being offered and the unused using(s) from being highlighted, respectively.

like image 83
Ian Kemp Avatar answered Jan 02 '23 01:01

Ian Kemp