VS2010:自动生成的文件和XML文档 [英] VS2010: Autogenerated files and XML documentation

本文介绍了VS2010:自动生成的文件和XML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上只是在重新询问此问题被问到有关Visual Studio 2008的问题. VS2010是否提供任何功能来消除针对自动生成的代码的CS1591编译器警告?

This is really just re-asking this question asked about Visual Studio 2008. Does VS2010 offer any feature to get rid of the CS1591 compiler warning for auto-generated code?

CS1591: Missing XML comment for publicly visible type or member

引用VS2008的问题:

To quote the question for VS2008:

这比一个更令人烦恼 问题.我的项目中包含一个数字 自动生成的文件(使用 mgmtclassgen.exe).当我生成 XML文档,我的美丽 注释的库被xml困扰 这些中的文档警告 自动生成文件.

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.

有没有一种方法可以抑制 为这些生成文档 文件或b)禁止显示警告CS1591 仅用于一组文件?我显然 不想修改以下文件 自动生成的,即使只是添加 压制实用主义.

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 Services生成的,因此产生错误的文件是自动生成的WebContext类(MyProject.BusinessApplication.Web.g.cs).

In my case, the offending files are generated by WCF RIA Services, so the file that is generating the errors is the auto-generated WebContext class (MyProject.BusinessApplication.Web.g.cs).

我无法手动修改此文件,因为它是即时生成的,所有更改都将被清除.我也不想全局禁用警告,因为它对我的非自动生成的代码很有帮助.

I cannot hand modify this file because it is generated on the fly, all changes will be wiped out. I also don't want to globally disable the warning, as it is helpful in my non-autogenerated code.

推荐答案

我在自动生成的实体框架类上遇到了类似的问题.我设法通过修改模板文件来解决它.显然,这不适用于所有自动生成的方案,并且可能不适用于您的特定RIA方案,但是我将在此处发布其他可能遇到相同问题的其他人.

I was having a similar issue with auto-generated entity framework classes. I managed to solve it by modifying the template file. This obviously won't work for all auto-generated scenarios and it may not apply to your particular RIA scenario, but I'll post here for anybody else that may be having the same issue.

打开模板文件(something.tt)并找到自动生成的xml注释部分

Open the template file (something.tt) and find the auto-generated xml comment section

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

在注释块之后添加以下行

Add the following line right after the comment block

#pragma warning disable 1591 

在此之下,您应该找到名称空间块的结束位置.可能看起来像这样

A little below that, you should find where the namespace block ends. It will probably look something like this

if (!String.IsNullOrEmpty(ObjectNamespace))
{
    PopIndent();
#>
}

在该大括号后面放置以下行

Place the following line after that closing brace

#pragma warning restore 1591

如果一切正常,则只要实体框架自动生成您的类,它们都应由disable/restore pragma语句包装.这应该在您的EF类中取消关于没有XML注释的警告,而不必在项目级别上取消警告.

If everything worked correctly, whenever your classes are auto-generated by Entity Framework, they should be wrapped by the disable/restore pragma statements. This should suppress the warnings about no XML comments in your EF classes without suppressing the warnings at the project level.

这篇关于VS2010:自动生成的文件和XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆