在 VS2017 代码分析中抑制外部 headers 的警告

Suppress warnings for external headers in VS2017 Code Analysis

我想在 Visual Studio 2017 中使用代码分析,但我使用的是 Qt,它给了我很多来自 headers 的警告。我试过关闭警告:

#pragma warning(push, 0)
#include <QtGlobal>
#pragma warning(pop)

但这并没有帮助。我也尝试使用 this:

#include <codeanalysis\warnings.h>
#pragma warning(push, 0)
#pragma warning(disable : ALL_CODE_ANALYSIS_WARNINGS)
#include <QtGlobal>
#pragma warning(pop)

但没有帮助。如何禁用 Qt 外部代码分析 headers?

如果您打开 .vcxproj 文件,在底部您应该看到:

  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>

在此下方您可以添加:

  <PropertyGroup Condition="'$(Language)'=='C++'">
    <IncludePath>$(QTDIR)\include;.\GeneratedFiles;$(IncludePath)</IncludePath>
    <CAExcludePath>$(QTDIR)\include;.\GeneratedFiles;$(CAExcludePath)</CAExcludePath>
  </PropertyGroup>

Microsoft 说存在 CAExcludePathIncludePath 覆盖的错误,但这在 Visual Studio 2017 V15.3 中已修复,您只需要设置 CAExcludePath - 我还没有'验证了这一点(我会在验证后更新)。

此回答来自How can I suppress warnings for external headers in VS2017 Code Analysis?