Home > Back-end >  (Visual Studio) how to detect unused imports?
(Visual Studio) how to detect unused imports?

Time:03-30

using System.Text; // If unused using directive turn gray.
using System.Threading.Tasks; // If unused using directive turn gray.
using System.Windows;

The unused using directive turn gray.
What kind of settings should I set up in the visual studio?
For detect the unused using directive immediately

I tried => go to Tool-Setting-Text editor, then check to using set
But I failed

I asking "How to fade about unused using"

CodePudding user response:

  1. You could remove all at the same time and organize things by right click in the editor and press -> "Remove and Sort usings (CTRL R, CTRL G) (default I think). This works for the current file.

  2. If you want to get a warning you could create a file in your solution named .editorconfig

[*.{cs,vb}]

IDE0005: Remove unnecessary imports dotnet_diagnostic.IDE0005.severity = warning"


Then set analysis setting to "Entire solution" like in the image below. Hope it helps.

enter image description here

  • Related