[英]Stop VS from automatically adding using directives
I don't mind the using directives which are automatically created when the script is created.我不介意在创建脚本时自动创建的 using 指令。 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!
我说的是 using 指令,当我在编码时,只要我引用了 scope 之外的类型,就会在脚本顶部自动生成这些指令。沉默的恶魔身上长了一个痘!
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.我只是更喜欢手动添加我的命名空间。
Under Tools > Options... > Text Editor > C# > IntelliSense, uncheck 'Show items from unimported namespaces (experimental)'.在工具 > 选项... > 文本编辑器 > C# > IntelliSense 下,取消选中“显示未导入命名空间中的项目(实验性)”。
Even I find this annoying.即使我觉得这很烦人。 I was able to turn this off in VS 2022 using the following options.
我可以使用以下选项在 VS 2022 中将其关闭。 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.我同意微软应该给我们一个选项来列出未导入命名空间中的项目,但不自动添加 using 语句。
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.在 Visual Studio 页面顶部,go 到工具 > 选项 > 文本编辑器 > C# > 高级 > 取消选中“粘贴时添加缺少的使用指令”选项,然后单击页面底部的确定。 And then restart Visual Studio.
然后重新启动 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 防止 Visual Studio 在复制粘贴时自动导入命名空间
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.