Search code examples
c#intellisensevisual-studio-2019

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?


Solution

  • I found the cause, and it's an annoying one!

    There is a custom ruleset specified for static analysis of the projects, and that had both CS8019 and IDE0005 (Unnecessary using directive) unselected.

    On selecting these the remove unused usings command worked again.

    Thanks to other answers for suggestions.