代码之家  ›  专栏  ›  技术社区  ›  Andrew Garrison

VS2010:自动生成的文件和XML文档

  •  19
  • Andrew Garrison  · 技术社区  · 15 年前

    this question asked about Visual Studio 2008 . VS2010是否提供了一些特性来消除自动生成代码的CS1591编译器警告?

    CS1591: Missing XML comment for publicly visible type or member

    引用VS2008的问题:

    这不仅仅是一个问题,更是一个烦恼 自动生成的文件(使用 XML文档,我的 注释库受到xml的困扰 自动生成文件。

    为这些生成文档 文件或b)抑制警告CS1591 不想修改 自动生成,即使只是添加

    编辑: 在我的例子中,有问题的文件是由WCF RIA服务生成的,因此生成错误的文件是自动生成的WebContext类( MyProject.BusinessApplication.Web.g.cs

    我不能手工修改这个文件,因为它是动态生成的,所有更改都将被删除。我也不想全局禁用警告,因为它对我的非自动生成代码很有帮助。

    4 回复  |  直到 9 年前
        1
  •  12
  •   Tallek    13 年前

    我在自动生成实体框架类时遇到了类似的问题。我通过修改模板文件解决了这个问题。这显然不适用于所有自动生成的场景,也可能不适用于您的特定RIA场景,但我将在这里为可能有相同问题的其他人发布。

    打开模板文件(什么。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>
    //------------------------------------------------------------------------------
    

    在注释块后面添加以下行

    #pragma warning disable 1591 
    

    再往下一点,您应该可以找到名称空间块的结束位置。可能看起来像这样

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

    #pragma warning restore 1591
    

    如果一切正常,只要实体框架自动生成类,就应该用disable/restore pragma语句包装它们。这应该抑制关于EF类中没有XML注释的警告,而不抑制项目级别的警告。

        2
  •  2
  •   satnhak    12 年前

    以下文章可能会为您提供一些解决问题的技巧: http://lvquoc.blogspot.com/2010/11/disable-xml-comment-warning-in-workflow.html

    本文的重要部分是Alan McBee的评论:要禁用在windows工作流VS2012+中生成的警告,请将此添加到项目文件的底部:

    <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
  •  1
  •   Tomasz Pluskiewicz    14 年前

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

    我刚把这事发到网上了 my blog

        4
  •  0
  •   Nayan_07    10 年前

    我也面临着类似的问题。我所做的是在任何一个页面上,如果名称空间没有任何XML注释,只要添加下面的代码行,就不会遇到类似的错误。

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