Issue with Global.asax.cs file and StyleCop rule SA1649

試著忘記壹切 提交于 2019-12-12 20:27:41

问题


Currently I'm working on a project at work and we're looking at upgrading our StyleCop from version 4.3.3 to 4.5

During the fun of all that, we've come across rule SA1649 - "FileHeaderFileNameDocumentationMustMatchTypeName" which is all nice and that, but causes issues with Global.asax.cs files, in that the file

// --------------------------------------------------------------------------------------------------------------------
// <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
    {
        ....
    }
}

Is being complained about because the file name 'Global.asax.cs' and the class 'MvcApplication' don't match. We've tried to put a supress list for 'Global.asax.cs' in the sylecop settings but this didn't seem to work. (Currently our work around is to disable the rule entirely but we don't want to keep that as the case, we only want the exception for Global.asax.cs files.)


回答1:


Found it out with a bit of time and manipulation of the original tool generated file.

<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>

Hope this helps out anyone else with this issue.




回答2:


Use a namespace level suppression:

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

namespace MyNamespace
{

}


来源:https://stackoverflow.com/questions/7796073/issue-with-global-asax-cs-file-and-stylecop-rule-sa1649

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!