简体   繁体   English

如何使用VS2012代码分析工具全局排除某个消息的错误?

[英]How do I globally exclude an error for a certain message with the VS2012 code analysis tool?

I'm currently getting the following messages from the VS2012 code analysis tool: 我目前从VS2012代码分析工具收到以下消息:

CA1709 Identifiers should be cased correctly In member 'Action.ExecuteAction(string, string)', correct the casing of 'ID' in parameter name 'merchantID' by changing it to 'Id'. CA1709标识符应正确套装在成员'Action.ExecuteAction(string,string)'中,通过将参数名称'merchantID'更改为'Id'来更正'ID'的大小写。 'Id' is an abbreviation and therefore is not subject to acronym casing guidelines. 'Id'是缩写,因此不受首字母缩略词套管指南的约束。

I have this defined in my GlobalSuppressions.cs file: 我在GlobalSuppressions.cs文件中定义了这个:

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(
    "Microsoft.Naming", 
    "CA1709:IdentifiersShouldBeCasedCorrectly", 
    MessageId = "ID", 
    Scope = "Global")]

How can I define a rule that says "ignore this specific spelling (I want ID, not Id) in all files"? 如何在所有文件中定义“忽略此特定拼写(我想要ID,而不是Id)”的规则“?

EDIT: Mike's solution worked, this is what I ended up with: 编辑:迈克的解决方案有效,这就是我最终的结果:

<?xml version="1.0" encoding="utf-8" ?>
<Dictionary>
    <Acronyms>
        <CasingExceptions>
            <Acronym>ID</Acronym>
        </CasingExceptions>
    </Acronyms>
</Dictionary>

What you're going to want to do, I believe , is add an acronym for ID to a custom dictionary and then you'll be able to drop the global suppression. 我相信 ,你想要做的是在自定义字典中添加ID的首字母缩写,然后你就可以放弃全局抑制。 Follow these instructions to do so. 请按照这些说明进行操作。

But, in short, here is a snippet pulled from that document that should be what yours looks like a bit ... 但是,简而言之,这是从该文档中删除的片段,应该是你的看起来有点......

<Dictionary>
      <Acronyms>
         <CasingExceptions>
            <Acronym>ID</Acronym>   <!-- Identifier -->
            ...
         </CasingExceptions>
         ...
      </Acronyms>
      ...
</Dictionary>

... however, if it's not an acronym it's one of those categories. ...但是,如果它不是首字母缩略词,那么它就是其中一个类别。

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

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