VS2010: Autogenerated files and XML documentation

早过忘川 提交于 2019-12-03 11:11:12

问题


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

To quote the question for 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.

EDIT: 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.


回答1:


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.

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

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.




回答2:


The following article may trigger you some tips to solve the issue: http://lvquoc.blogspot.com/2010/11/disable-xml-comment-warning-in-workflow.html

The important part of the article is the comment by Alan McBee: for disabling the warnings generated in windows workflow VS2012+ add this to the bottom of your project file:

<Target Name="XamlGeneratedCodeWarningRemoved" AfterTargets="MarkupCompilePass2">
  <Exec Command="for %%f in (@(_GeneratedCodeFiles)) do echo #pragma warning disable 1591 > %%f.temp" />
  <Exec Command="for %%f in (@(_GeneratedCodeFiles)) do type %%f >> %%f.temp" />
  <Exec Command="for %%f in (@(_GeneratedCodeFiles)) do echo #pragma warning restore 1591 >> %%f.temp" />
  <Exec Command="for %%f in (@(_GeneratedCodeFiles)) do move /y %%f.temp %%f" />
  <Message Text="Xaml Generated Code Warnings Removed: @(_GeneratedCodeFiles)" />
</Target>



回答3:


Simmilarily to Quam Loc's solution it is possible to disable warnings in RIA generated files using a build target:

<Target Name="CreateRiaClientFilesTaskDisableWarnings" AfterTargets="CreateRiaClientFiles">
  <Exec Command="for %%f in (@(RiaClientGeneratedFiles)) do echo #pragma warning disable &gt; %%f.temp" />
  <Exec Command="for %%f in (@(RiaClientGeneratedFiles)) do type %%f &gt;&gt; %%f.temp" />
  <Exec Command="for %%f in (@(RiaClientGeneratedFiles)) do attrib -r %%f" />
  <Exec Command="for %%f in (@(RiaClientGeneratedFiles)) do move /y %%f.temp %%f" />
  <Exec Command="for %%f in (@(RiaClientGeneratedFiles)) do attrib +r %%f" />
  <Message Text="CreateRiaClientFilesTaskDisableWarnings: @(RiaClientGeneratedFiles)" />
</Target>

I've just posted about it on my blog.




回答4:


I was facing similar issue. What I did was in whichever page if there aren't any XML Comments for the Namespace, just add the below line of code and you wont face similar error.

'/// <summary>
/// Namespace provides implementation for ABC classes.
/// </summary>
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
class NamespaceDoc
{
}'


来源:https://stackoverflow.com/questions/3630282/vs2010-autogenerated-files-and-xml-documentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!