【问题标题】:Disable StyleCop Rule with VS2012 Express使用 VS2012 Express 禁用 StyleCop 规则
【发布时间】:2013-11-17 04:57:06
【问题描述】:

我使用的是 Visual Studio 2012 Express,因此无法访问普通版 VS 的集成。我使用了MSBuild to integrate StyleCop,规则显示为警告。我希望能够禁用规则。 Disabling StyleCop rules 帖子表明这是可能的,但我无法理解建议编辑 Settings.StyleCop 文件的答案。但是,我不明白需要添加到此文件以禁用规则。

如果我想禁用规则SA1649,例如,我将如何更新以下文件?

<StyleCopSettings Version="4.3">
  <GlobalSettings>
    <CollectionProperty Name="DeprecatedWords">
      <Value>preprocessor,pre-processor</Value>
      <Value>shortlived,short-lived</Value>
    </CollectionProperty>
  </GlobalSettings>
  <Parsers>
    <Parser ParserId="StyleCop.CSharp.CsParser">
      <ParserSettings>
        <CollectionProperty Name="GeneratedFileFilters">
          <Value>\.g\.cs$</Value>
          <Value>\.generated\.cs$</Value>
          <Value>\.g\.i\.cs$</Value>
        </CollectionProperty>
      </ParserSettings>
    </Parser>
  </Parsers>
  <Analyzers>
    <Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
      <AnalyzerSettings>
        <CollectionProperty Name="Hungarian">
          <Value>as</Value>
          <Value>do</Value>
          <Value>id</Value>
          <Value>if</Value>
          <Value>in</Value>
          <Value>is</Value>
          <Value>my</Value>
          <Value>no</Value>
          <Value>on</Value>
          <Value>to</Value>
          <Value>ui</Value>
        </CollectionProperty>
      </AnalyzerSettings>
    </Analyzer>
  </Analyzers>
</StyleCopSettings>

注意:我使用的是 4.7 版本,即使默认设置文件显示的是 4.3

【问题讨论】:

    标签: visual-studio-2012 msbuild stylecop rule


    【解决方案1】:

    将以下代码粘贴到记事本中并保存为 settings.StyleCop 并将其放入解决方案文件夹并构建

    <StyleCopSettings Version="105">
      <GlobalSettings>
        <BooleanProperty Name="RulesEnabledByDefault">False</BooleanProperty>
      </GlobalSettings>
    </StyleCopSettings>
    

    【讨论】:

      【解决方案2】:

      我找到了edit a stylecop rule in the XML的以下文档

      XML 代码 sn-p 如下。

      <StyleCopSettings Version="4.3">
        <Analyzers>
          <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.LayoutRules">
            <Rules>
              <Rule Name="StatementMustNotBeOnSingleLine">
                <RuleSettings>
                  <BooleanProperty Name="Enabled">False</BooleanProperty>
                </RuleSettings>
              </Rule>
              <Rule Name="ElementMustNotBeOnSingleLine">
                <RuleSettings>
                  <BooleanProperty Name="Enabled">False</BooleanProperty>
                </RuleSettings>
              </Rule>
            </Rules>
            <AnalyzerSettings />
          </Analyzer>
        </Analyzers>
      </StyleCopSettings>
      

      此外,我还发现您可以将Settings.Sytlecop 文件拖到StyleCopSettingsEditor.exe 上,该StyleCopSettingsEditor.exe 提供了用于启用和禁用规则的GUI。

      【讨论】:

        猜你喜欢
        • 2010-10-13
        • 2015-04-02
        • 1970-01-01
        • 2021-10-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多