Search code examples
.netvisual-studio-2010stylecop

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


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


Solution

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