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

发布于 2024-12-10 21:58:09 字数 1031 浏览 2 评论 0原文

目前我正在开发一个项目,我们正在考虑将 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 文件例外。)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一个人练习一个人 2024-12-17 21:58:09

使用命名空间级别抑制:

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

namespace MyNamespace
{

}

Use a namespace level suppression:

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

namespace MyNamespace
{

}
囚我心虐我身 2024-12-17 21:58:09

经过一些时间和对原始工具生成的文件的操作发现了它。

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

希望这可以帮助其他人解决这个问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文