Global.asax.cs文件和StyleCop规则SA1649的问题

时间:2011-10-17 15:34:11

标签: .net visual-studio-2010 stylecop

目前我正在开展一个工作项目,我们正在考虑将StyleCop从版本4.3.3升级到4.5

在所有这些的乐趣中,我们遇到了规则SA1649 - “FileHeaderFileNameDocumentationMustMatchTypeName”这很好,但是会导致Global.asax.cs文件出现问题,因为文件

// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Global.asax.cs" company="COMPANY">
//   Copyright (c) COMPANY. All rights are reserved.....
// </copyright>
// <summary>
//   Starting point for back office website.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Foo.Web
{
    /// <summary>
    /// Starting point for back office website.
    /// </summary>
    public class MvcApplication : HttpApplication
    {
        ....
    }
}

因为文件名'Global.asax.cs'和类'MvcApplication'不匹配而受到抱怨。我们试图在sylecop设置中放入'Global.asax.cs'的抑制列表,但这似乎不起作用。 (目前我们的工作是完全禁用规则,但我们不希望保持这种情况,我们只想要Global.asax.cs文件的例外。)

2 个答案:

答案 0 :(得分:3)

通过一些时间和操作原始工具生成的文件找到它。

<StyleCopSettings Version="105">
  <Analyzers>
  ... Removed for brevity ...
  </Analyzers>
  <SourceFileList>
        <SourceFile>Global.asax.cs</SourceFile>
        <Settings>
            <Analyzers>
                <Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
                    <Rules>
                        <Rule Name="FileHeaderFileNameDocumentationMustMatchTypeName">
                          <RuleSettings>
                            <BooleanProperty Name="Enabled">False</BooleanProperty>
                          </RuleSettings>
                        </Rule>
                    </Rules>
                </Analyzer>
            </Analyzers>
        </Settings>
    </SourceFileList>
</StyleCopSettings>

希望这有助于解决这个问题。

答案 1 :(得分:3)

使用命名空间级别抑制:

[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:FileHeaderFileNameDocumentationMustMatchTypeName", Justification = "Reviewed.")]

namespace MyNamespace
{

}