风格警察 SA1638

发布于 2024-08-24 01:25:21 字数 629 浏览 12 评论 0原文

我在 VS2008 中使用 StyleCop。我收到此错误:

SA1638:文件头的版权标记中的文件属性必须包含文件的名称。

这是我的标头。

// <copyright file="AssemblyInfo.cs" company="company">
// Copyright (c) company. All rights reserved.
// </copyright>
// <author>me</author>
// <email>[email protected]</email>
// <date>2010-03-04</date>
// <summary>blah blah.</summary>

我怀疑问题是我的 AssemblyInfo.cs 位于 Properties 文件夹内。有什么线索可以告诉我如何在不沉默 StyleCop 的情况下修复此警告吗?

I am using StyleCop in VS2008. I get this error:

SA1638: The file attribute in the file header's copyright tag must contain the name of the file.

Here is my header.

// <copyright file="AssemblyInfo.cs" company="company">
// Copyright (c) company. All rights reserved.
// </copyright>
// <author>me</author>
// <email>[email protected]</email>
// <date>2010-03-04</date>
// <summary>blah blah.</summary>

I suspect the problem is that my AssemblyInfo.cs is located inside the Properties folder. Any clues to how I can fix this warning without silencing StyleCop?

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

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

发布评论

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

评论(6

伤痕我心 2024-08-31 01:25:21

在“解决方案资源管理器”中选择该文件,右键单击“属性”窗口,复制“文件名”区域中的文本,将其粘贴到标题中。

Properties 目录应该不重要,我假设你在某个地方有一个拼写错误。

添加:
如果这不起作用,那么要修复它,您必须将其提升到一个新的水平。
将整个项目复制到新的解决方案,使用 StyleCop 重新扫描。
删除所有不相关的文件,用StyleCop重新扫描。
删除问题文件中除标题之外的所有代码,用 StyleCop 重新扫描。
如果问题在途中的某个地方消失了,那就真的很奇怪了。
如果问题没有消失,那么您就得到了可重现的样本!

压缩该示例并将其附加到此处的新工作项: http:// code.msdn.microsoft.com/sourceanalysis/WorkItem/List.aspx

假以时日,可能会发布新版本来修复该错误。 8)

Select the file in Solution Explorer, open the right-click Properties window, copy the text in the "File Name" area, paste that into the header.

The Properties directory shouldn't matter, I'd assume you've got a typo in there somewhere.

Addition:
If that doesn't work, then to fix it you'll have to take it to the next level.
Copy the whole project to a new solution, re-scan with StyleCop.
Delete all unrelated files, re-scan with StyleCop.
Delete all code in the problem file except the header, re-scan with StyleCop.
If the problem disappears somewhere along the way, that would be really weird.
If the problem doesn't disappear, then you've got a reproducible sample!

Zip up that sample and attach it to a new work item here: http://code.msdn.microsoft.com/sourceanalysis/WorkItem/List.aspx

Given some time there will likely be a new release to fix the bug. 8 )

疑心病 2024-08-31 01:25:21

我的 Properties 文件夹中的 AssemblyInfo.cs 文件有以下内容:

// <copyright file="AssemblyInfo.cs" company="company">
// product
// Copyright (c) 2004-2010
// by company ( http://www.example.com )
// </copyright>

并且它没有任何问题。您确定文件名正确(也许大小写已关闭?)并且您没有任何无效的 XML(也许是您公司名称中的“&”符号)?

I have the following for an AssemblyInfo.cs file in the Properties folder:

// <copyright file="AssemblyInfo.cs" company="company">
// product
// Copyright (c) 2004-2010
// by company ( http://www.example.com )
// </copyright>

And it doesn't have any problems with that. Are you sure that you the file name is correct (maybe casing is off?) and that you don't have any invalid XML (an ampersand in your company name, perhaps)?

说好的呢 2024-08-31 01:25:21

根据 StyleCop 文档,现在您可以这样处理 AssemblyInfo.cs

完全由工具自动生成的文件,不应检查或强制执行由 StyleCop 提供,可以包含“自动生成”标头而不是标准文件标头。这将导致 StyleCop 忽略该文件。这种类型的标头不应放置在手动编写的代码文件之上。

// <auto-generated />
namespace Sample.Something
{
    // The contents of this file are completely auto-generated by a tool.
}

According to StyleCop Documentation, this is how you would handle AssemblyInfo.cs nowadays:

A file that is completely auto-generated by a tool, and which should not be checked or enforced by StyleCop, can include an “auto-generated” header rather than the standard file header. This will cause StyleCop to ignore the file. This type of header should never be placed on top of a manually written code file.

// <auto-generated />
namespace Sample.Something
{
    // The contents of this file are completely auto-generated by a tool.
}
从来不烧饼 2024-08-31 01:25:21

原因是文件名与该文件内的类名不同。使文件名和类名相同可以解决此问题。

The reason is the file name is different from the class name inside that file. Make the file name and class name the same will fix this issue.

╰沐子 2024-08-31 01:25:21

最可能的问题是您的文件名和类名不同。
如果您可以将类更新为部分类,则 StyleCop 不会显示此错误。

most probably issue is your File name and Class name is different.
If you can update your class as partial then this error will not show from StyleCop.

苏佲洛 2024-08-31 01:25:21

文件名和类应该相同。

请在文件头文档之后使用它。它将解决问题。

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

The filename and class should be same.

please use this after file header documentation.It will fix the issues.

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

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