简体   繁体   English

阻止 VS 自动添加 using 指令

[英]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.

相关问题 阻止 Visual Studio 将 using 指令置于命名空间之外 - Stop Visual Studio from putting using directives outside namespace 如果它们实际上在预处理器指令中使用,如何阻止 VS 删除“未使用”的命名空间? - How to stop VS from removing “unused” namespaces if they are actually used in preprocessor directives? 如何阻止select tag helper自动添加'multiple'属性 - How to stop select tag helper from automatically adding 'multiple' attribute 在保存时自动调用visual studio 2008“使用指令排序”? - Automatically call visual studio 2008 “sort using directives” on save? 如何让Intellisense自动解决丢失的Using指令 - How to get Intellisense to automatically resolve missing Using directives 如何在格式化时自动移动命名空间内的 using 指令? - How to automatically move the using directives inside the namespace on formatting? VS2010/C# 中的全局“使用”指令? - Global "using" directives in VS2010/C#? 实现抽象类,同时添加必要的using指令 - Implementing abstract classes while adding the necessary using directives 使用指令 - Using Directives 预处理程序指令和不必要的Using指令 - Preprocessor directives and unnecessary Using directives
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM