简体   繁体   English

如何从VS2015中的分析中排除GlobalSuppressions.cs

[英]How to exclude GlobalSuppressions.cs from analysis in VS2015

Currently I'm trying the new Code Analysis features in Visual Studio 2015. This feature enables developers to suppress active issues. 当前,我正在尝试Visual Studio 2015中的新代码分析功能。此功能使开发人员可以消除活动问题。 Issues are suppressed using the SuppressMessageAttribute, which can be applied in the source code itself or in a separate suppressions file, which Visual Studio creates in the project root by the name 'GlobalSuppressions.cs'. 使用SuppressMessageAttribute可以抑制问题,该属性可以应用在源代码本身中,也可以应用在单独的抑制文件中,Visual Studio在项目根目录中通过名称“ GlobalSuppressions.cs”创建了该文件。

However when I use such a (generated) suppression file, this file itself becomes subject to analysis itself and subsequently causing analyses errors. 但是,当我使用这种(生成的)抑制文件时,该文件本身将受到分析本身的影响,从而导致分析错误。 I cannot find anything about preventing this. 我找不到任何防止这种情况的方法。 Is there any way to exclude this 'GlobalSuppressions.cs' file from Code Analysis altogether? 有什么办法可以将“ GlobalSuppressions.cs”文件完全排除在代码分析之外?

Perhaps noteworthy, I'm using the NuGet package StyleCop.Analyzers for additional analyzer rules. 也许值得注意的是,我正在使用NuGet包StyleCop.Analyzers来获取其他分析器规则。

Two options: 两种选择:

  • Put this at the top of GlobalSuppressions.cs // <auto-generated /> 将其放在GlobalSuppressions.cs的顶部// <auto-generated />

  • For just for StyleCop: 仅用于StyleCop:

Alter the csproj to have for the file: 更改文件的csproj:

  <Compile Include="GlobalSuppressions.cs">
    <ExcludeFromStyleCop>True</ExcludeFromStyleCop>
 </Compile>

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

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