Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Visual Studio from adding using statements (Visual Studio 2022 edition)

This question comes up a lot, is there any way to get Microsoft's attention and convince them to stop inserting this extremely annoying feature?

If I have a C# file that doesn't currently use System.Collections.Generic, and I type a line like this:

List<string> moose = new();

VS then happily inserts

using iTextSharp.text;

which is of course completely wrong.

I swear it's like Clippy all over again but without checking before making any changes.

There is an option in the Tools menu that other questions say should control this feature, but apparently Microsoft left the option in but ignores the value (although to be fair I'm not pasting anything):

enter image description here

There is another question that does say "tab completion will still auto-add missing using directives" but in my case I'm not tab-completing. I'm just typing in the line of code.

Has anyone found a way to disable this "feature"?

like image 441
Betty Crokker Avatar asked Apr 26 '26 03:04

Betty Crokker


1 Answers

I followed the "report a problem with VS" link and got a response within about a day! Their initial answer was that the "Show items from unimported namespaces" option does what I want. Unchecking that did indeed disable the insertion of the 'using' statement.

I did submit a follow-up bug asking that they fix the text of the option, as "show items from unimported namespaces" does not at all indicate "and add using statements".

enter image description here

like image 90
Betty Crokker Avatar answered Apr 28 '26 17:04

Betty Crokker