Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove and Sort Usings not working in Visual Studio 2019

On a certain solution the "Remove and Sort Usings" option does not work. It sorts the Usings correctly, but does not remove any unnecessary ones. The IDE is flagging the unused ones correctly, but it can't seem to remove them. No errors or messages are displayed anywhere, it sorts and behaves like it has completed successfully, but the unnecessary Usings remain and are still flagged by Intellisense as such.

I have verified that in a different solution it does work, so it is not my VS2019 install. And I don't have any plugins installed (like Resharper) that could conflict. Have also tried clean and rebuild in case it needed an error-free compilation to work with.

Any ideas what could be different/special about a certain solution that would prevent the remove functionality?

like image 807
KrustyGString Avatar asked Mar 26 '20 23:03

KrustyGString


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.

How do I sort in Visual Studio?

Select Edit from the menu bar. Select Intellisense > Sort Usings. You can also configure different settings for using directives in Tools > Options > Text Editor > C# > Advanced.


1 Answers

I have found another thing which causes this issue.

For me, I discovered it was only happening in 1 particular project in a solution.

After comparing the non-working csproj to a working one, I determined that the difference was the Warning Level.

The non-working one was set to 1.

Resetting this to the default 4 allows the Remove and Sort Usings function to work as expected.

like image 85
Shevek Avatar answered Sep 28 '22 12:09

Shevek