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

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

I want to use the Code Analysis in Visual Studio 2017 but I'm using Qt and it gives me a lot of warnings from the headers. I've tried turning off warnings:

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

但这无济于事.我还尝试使用 这个:

but it doesn't help. I also tried using this:

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

但没有帮助.如何禁用 Qt 外部头文件的代码分析?

but no help. How can I disable the Code Analysis for the Qt external headers?

推荐答案

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

If you open your .vcxproj file, down the bottom you should see:

  <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 - 我还没有验证这个(我会在我更新这个做).

Microsoft say there's a bug where CAExcludePath is overwritten by IncludePath but this is fixed in Visual Studio 2017 V15.3 and you'll only need to set CAExcludePath - I haven't verified this (I'll update this once I do).

这个答案来自 如何在 VS2017 代码分析中抑制外部标头的警告?

相关文章