[英]Remove and Sort Usings not working in Visual Studio 2019
On a certain solution the "Remove and Sort Usings" option does not work.在某个解决方案中,“删除和排序使用”选项不起作用。 It sorts the Usings correctly, but does not remove any unnecessary ones.它正确排序使用,但不会删除任何不必要的。 The IDE is flagging the unused ones correctly, but it can't seem to remove them. IDE 正在正确标记未使用的那些,但它似乎无法删除它们。 No errors or messages are displayed anywhere, it sorts and behaves like it has completed successfully, but the unnecessary Usings remain and are still flagged by Intellisense as such.任何地方都不会显示任何错误或消息,它的排序和行为就像它已经成功完成一样,但不必要的使用仍然存在,并且仍然被 Intellisense 标记为这样。
I have verified that in a different solution it does work, so it is not my VS2019 install.我已经验证在不同的解决方案中它确实有效,所以它不是我的 VS2019 安装。 And I don't have any plugins installed (like Resharper) that could conflict.而且我没有安装任何可能发生冲突的插件(如 Resharper)。 Have also tried clean and rebuild in case it needed an error-free compilation to work with.还尝试过清理和重建,以防它需要无错误的编译来使用。
Any ideas what could be different/special about a certain solution that would prevent the remove functionality?任何想法可能会阻止删除功能的某个解决方案有什么不同/特殊之处?
I have found another thing which causes this issue.我发现了导致此问题的另一件事。
For me, I discovered it was only happening in 1 particular project in a solution.对我来说,我发现它只发生在解决方案中的 1 个特定项目中。
After comparing the non-working csproj to a working one, I determined that the difference was the Warning Level.在将不工作的 csproj 与工作的 csproj 进行比较后,我确定差异是警告级别。
The non-working one was set to 1.非工作的设置为 1。
Resetting this to the default 4 allows the Remove and Sort Usings function to work as expected.将其重置为默认值 4 允许删除和排序使用功能按预期工作。
I found the cause, and it's an annoying one!我找到了原因,这很烦人!
There is a custom ruleset specified for static analysis of the projects, and that had both CS8019 and IDE0065 (Unnecessary using directive) unselected.为项目的静态分析指定了一个自定义规则集,并且未选择 CS8019 和 IDE0065(不必要的使用指令)。
On selecting these the remove unused usings command worked again.选择这些后,删除未使用的 using 命令再次起作用。
Thanks to other answers for suggestions.感谢其他答案的建议。
Any ideas what could be different/special about a certain solution that would prevent the remove functionality?任何想法可能会阻止删除功能的某个解决方案有什么不同/特殊之处?
This is quite a strange behavior.这是一个相当奇怪的行为。 You could try these suggestions:你可以试试这些建议:
1) close VS Instance, delete .vs
hidden folder, bin
, obj
folder. 1)关闭 VS Instance,删除.vs
隐藏文件夹、 bin
、 obj
文件夹。
2) clean vs component caches under C:\\Users\\xxx\\AppData\\Local\\Microsoft\\VisualStudio\\16.0_xxxx(every this folder)\\ComponentModelCache
2)清理C:\\Users\\xxx\\AppData\\Local\\Microsoft\\VisualStudio\\16.0_xxxx(every this folder)\\ComponentModelCache
下的 vs 组件缓存
3) use devenv /safemode to start VS IDE, open your project and then test again. 3)使用devenv /safemode启动 VS IDE,打开你的项目,然后再次测试。
4) If your project is an old project which means that the project structure is a bit different from VS2019, please try to create a new vs2019 project and then migrate its content into the new project. 4)如果你的项目是旧项目,这意味着项目结构与VS2019有点不同,请尝试创建一个新的vs2019项目,然后将其内容迁移到新项目中。
In addition , if these do not work, you can try this link's function to run Code Cleanup command with remove unused usings
.此外,如果这些都不起作用,您可以尝试使用此链接的功能运行代码清理命令并remove unused usings
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.