简体   繁体   English

在 Visual Studio 中显示代码警告

[英]Showing code Warnings in Visual Studio

I'm trying to improve code quality on a program using Visual Studio Enterprise 2015. The Error List is empty, but if I open specific files, then it shows warnings.我正在尝试使用 Visual Studio Enterprise 2015 提高程序的代码质量。错误列表为空,但如果我打开特定文件,则会显示警告。 The only active filter I have is the "Current Project", so I don't understand why is it not showing those warnings by default, but only when I open the files themselves.我拥有的唯一活动过滤器是“当前项目”,所以我不明白为什么默认情况下它不显示这些警告,而是仅在我自己打开文件时才显示。 How can I make VS show all the warnings even for closed files?我怎样才能让 VS 显示所有警告,即使是关闭的文件?

Another question, I did "Run Code Analysis and suppress active issues" and I've lost the ones from the previous run.另一个问题,我做了“运行代码分析并抑制活动问题”,但我丢失了上次运行中的问题。 How can I revert this suppressor?我怎样才能恢复这个抑制器?

EDIT: One of the warnings I see when opening the file says the following:编辑:我在打开文件时看到的警告之一如下:

RECS0065: Expression is always false RECS0065:表达式始终为 false

And refers to this section of the code:并参考这部分代码:

if (sourceProject.uid == null
  && row[fieldConfig.ImportFieldName].GetType() == typeof(Guid)
  && (fieldConfig.ODataFieldName == "ProjectId"))

The expression will always be evaluated to false because the sourceProject.uid is always null at this stage.该表达式将始终评估为 false,因为在此阶段 sourceProject.uid 始终为 null。

Now, back to the main question what happens is that if I close the file, then the warning disappears from the Error List.现在,回到主要问题,如果我关闭文件,警告就会从错误列表中消失。 I want to see these warnings even if the files are not opened in the Editor.即使文件未在编辑器中打开,我也希望看到这些警告。

This is the kind of warnings that I'm trying to clean, basically just bad coding.这是我试图清除的那种警告,基本上只是糟糕的编码。 My question is not asking how to solve the errors, but how to always visualise them.我的问题不是问如何解决错误,而是如何始终将它们可视化。

In my Visual Studio 2017 (v15.2), I only see all of the warnings across all files in my solution after doing a "Rebuild All" from the Build menu.在我的 Visual Studio 2017 (v15.2) 中,从“构建”菜单执行“全部重建”后,我只能看到解决方案中所有文件的所有警告。

Most of the warnings disappear again after doing a regular Build ( Ctrl + Shift +B).执行常规构建( Ctrl + Shift + B)后,大多数警告再次消失。

I get this behavior regardless of whether the Full Solution Analysis option is enabled.无论是否启用了完整解决方案分析选项,我都会得到这种行为。

To show all CA warnings see this要显示所有 CA 警告,请参阅

To revert surpressions delete GlobalSurpressions.cs file.要恢复GlobalSurpressions.cs删除GlobalSurpressions.cs文件。

Update in visual studio 2019 professional You can select the scope of the error list in the left top corner of the error list window在visual studio 2019专业版更新您可以在错误列表窗口的左上角选择错误列表的范围

  • current document当前文件
  • current project当前项目
  • ... ...

Error list window错误列表窗口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM