这真的只是重新询问 this question asked about Visual Studio 2008 . VS2010 是否提供任何功能来消除自动生成代码的 CS1591 编译器警告?CS1591: Missing XML comment for publicly visible type or member
引用 VS2008 的问题:
This is an annoyance more than a problem. My project contains a number of autogenerated files (using mgmtclassgen.exe). When I generate the XML documentation, my beautifully commented library is plagued by xml documentation warnings from these autogen files.
Is there a way to either a) suppress generating documentation for these files or b) suppress warning CS1591 just for a set of files? I obviously do not want to modify files that are autogenerated, even if to just add suppression pragmas.
编辑:
在我的例子中,有问题的文件是由 WCF RIA 服务生成的,因此生成错误的文件是自动生成的 WebContext 类 (
MyProject.BusinessApplication.Web.g.cs
)。我无法手动修改此文件,因为它是动态生成的,所有更改都将被清除。我也不想全局禁用警告,因为它对我的非自动生成代码很有帮助。
最佳答案
我对自动生成的 Entity Framework 类有类似的问题。我设法通过修改模板文件来解决它。这显然不适用于所有自动生成的场景,也可能不适用于您的特定 RIA 场景,但我会在这里为可能遇到相同问题的其他人发帖。
打开模板文件(something.tt),找到自动生成的 xml 注释部分
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
在注释 block 之后添加以下行
#pragma warning disable 1591
再往下一点,您应该会找到命名空间 block 的结束位置。它可能看起来像这样
if (!String.IsNullOrEmpty(ObjectNamespace))
{
PopIndent();
#>
}
将以下行放在该右大括号之后
#pragma warning restore 1591
如果一切正常,只要你的类是由 Entity Framework 自动生成的,它们应该被 disable/restore pragma 语句包装。这应该抑制有关 EF 类中没有 XML 注释的警告,而不抑制项目级别的警告。
关于visual-studio-2010 - VS2010 : Autogenerated files and XML documentation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3630282/