Show unnecessary imports in the Visual Studio's error window

 
 
  • Gérald Barré

By default, Visual Studio shows unnecessary imports as faded text and provides a quick fix to remove them:

This means you have to check each file individually. You can also surface them in the error window for easier tracking:

Create a new file named .editorconfig at the root of your project with the following content:

.editorconfig
[*.{cs,vb}]

# IDE0002: Name can be simplified
dotnet_diagnostic.IDE0002.severity = suggestion

# IDE0005: Remove unnecessary imports
dotnet_diagnostic.IDE0005.severity = suggestion

You also need to configure Visual Studio to run background analysis on the entire solution:

You can change the severity of any IDE0000 rule by editing the .editorconfig file.

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?