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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With