Search code examples
c#visual-studiounity-game-enginenamespaces

Prevent Visual Studio from auto import namespace when copy paste


I am using Visual Studio with Unity. When I copy and paste a code in Visual Studio. It automatically adds an unnecessary namespace on the top. It is pretty annoying to see if there have many unused namespaces over time. May I ask if is this a bug or how can I turn off the auto import namespace when copy paste?

From the suggested name, I think Visual Studio confuses the "length" and "Length" enter image description here

Here are the steps to reproduce the problem

enter image description here


Solution

  • 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.

    Might be useful to some to note that tab completion will still auto-add missing using directives.

    enter image description here

    Here is an example with the option checked (the example specifics are not relevant but in this case an attribute is being pasted to an ASP.Net Core Razor Page): Checked Option

    Here is an example with the option unchecked: Unchecked option