Nate H.
Nate H.

Reputation: 1033

Stop VS from automatically adding using directives

I don't mind the using directives which are automatically created when the script is created. Those are fine. What I'm talking about are the using directives which are automatically generated at the top of the script while I'm coding as soon as I refer to a type which is out of scope. A pox upon the silent fiends!

To clarify, currently if I try including a type which exists in some namespace which is not yet declared as 'using' in the script, said namespace will get auto-added to the top of the script. This is undesired behavior for me.

I simply prefer to manually add my namespaces.

Upvotes: 81

Views: 20790

Answers (4)

Roshith S
Roshith S

Reputation: 351

In Visual Studio 2022, The option to stop VS from automatically importing the directories on paste has been moved under tools -> options -> text editor -> C# -> advanced. From here you could deselect the option. It is selected by default. Quite annoying ! Posting screenshot for reference : enter image description here

Upvotes: 25

MastaKwaa
MastaKwaa

Reputation: 719

On the top of the page in Visual Studio, go to Tools > Options > Text Editor > C# > Advanced > Uncheck the option for "Add missing using directives on paste" then click OK on the bottom of the page. And then restart Visual Studio.

Answer was originally posted (much better) here, but posted here since this is the top google result and didn't have the answer:

Prevent Visual Studio from auto import namespace when copy paste

Upvotes: 71

Shreedhar Kotekar
Shreedhar Kotekar

Reputation: 1114

Even I find this annoying. I was able to turn this off in VS 2022 using the following options. Hope this helps some one.

I do agree that Microsoft should give us an option to list the items from unimported namespaces but not add using statements automatically.

enter image description here

Upvotes: 6

Nate H.
Nate H.

Reputation: 1033

Under Tools > Options... > Text Editor > C# > IntelliSense, uncheck 'Show items from unimported namespaces (experimental)'.

Upvotes: 21

Related Questions