how to detect unused imports?

Visual Studio 2019 comes with default code cleanup that fixes this. Shortcut is to press CTRL+K and CTRL+E as default.

https://docs.microsoft.com/en-us/visualstudio/ide/code-styles-and-code-cleanup?view=vs-2019

enter image description here

You can also use the command "Remove and Sort Usings" with CTRL+R and CTRL+G.

enter image description here


Visual Studio has this feature built in if you want to remove them rather than just detect them: Automatic Code Generation -> Organize usings

The Remove Unused Usings option in the Visual Studio user interface removes using directives, using aliases, and extern aliases that are not used in the source code. There are two ways to call the operation:

  • Main Menu - On the Edit menu, point to IntelliSense, point to Organize Usings, and then click Remove Unused Usings.

  • Context Menu - Right-click anywhere inside the code editor, point to Organize Usings, and then click Remove Unused Usings.

Edit to include information from comments

Franci has chimed in with the Powershell extension to VS 2010 which adds in more functionality to do this task as well as others: http://visualstudiogallery.msdn.microsoft.com/en-us/e5f41ad9-4edc-4912-bca3-91147db95b99