对生成的C#代码剿警告 [英] supress warning for generated c# code

查看:148
本文介绍了对生成的C#代码剿警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经打开了将警告视为错误,这意味着我得到的错误丢失的文件(尼斯提醒这个特殊项目)为我的VS项目。

I have turned on "Treat warnings as errors" for my VS project which mean that I get errors for missing documentation (nice reminder for this particular project).

然而,由一个自定义的工具,所以我在寻找而去忽略而已,不是针对整个项目生成的代码缺少XML文档不插入XML文档生成的代码的一部分。我有上生成的实际的文件没有影响,并不能真正在文件中插入任何东西(因为它是由工具频繁地再生),所以我寻找现有生成的文件之外的东西(所生成的类是局部的,没有什么帮助)

However, part of the code is generated by a custom tool which does not insert xml documentation so I'm looking for away to ignore the missing xml documentation for the generated code only, not for the entire project. I have no influence on the actual file generated and cannot really insert anything in the file (as it is regenerated frequently by the tool) so I looking for something existing outside the generated file (the classes that are generated are partial, if that helps)

推荐答案

编辑:见说明此的的用C#工作4.我的意见尚不清楚是否在早期版本的编译器的工作。在C#4规格使得虽然这很清楚。 2.5.8.1条规定:

See comments indicating that this doesn't work with C# 4. I'm not clear whether it worked in earlier versions of the compiler. The C# 4 spec makes this pretty clear though. Section 2.5.8.1 states:

A 的#pragma警告恢复指令恢复所有或所述给定集合的警告,这是有效的编译单元的开始时的状态的。需要注意的是如果一个特定的警告是在外部禁用,的#pragma警告恢复(无论全部或指定警告)将不会重新启用该警告。

A #pragma warning restore directive restores all or the given set of warnings to the state that was in effect at the beginning of the compilation unit. Note that if a particular warning was disabled externally, a #pragma warning restore (whether for all or the specified warning) will not re-enable that warning.

杰夫拥有的解决办法在博客 - 基本上重新处理自动生成的代码作为构建的一部分

Jeff has a workaround in a blog post - basically to reprocess autogenerated code as part of the build.

随着汤姆说,你可以添加一个忽略整个项目(建设/抑制警告 - 输入1591作为警告编号) - 但你可以的恢复的在顶部的警告自己您的每一个的非生成的文件:

As Tom says, you can add an "ignore" to the whole project (Build / Suppress Warnings - enter 1591 as the warning number) - but then you can restore the warning yourself at the top of each of your non-generated files:

#pragma warning restore 1591

这是非常丑陋,但它工作(我只是测试它)。

It's pretty ugly, but it works (I've just tested it).

这篇关于对生成的C#代码剿警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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