MSDN > 論壇首頁 > Visual Studio Code Analysis and Code Metrics > Rule for generated code is ignored in FxCop 1.36 when it shouldn't be
發問發問
 

已答覆Rule for generated code is ignored in FxCop 1.36 when it shouldn't be

  • 2008年7月24日 下午 12:14Guy Smith-FerrierMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    I have a custom rule that checks generated code. The "Suppress analysis results against generated code" project setting is unchecked so I am expecting the rule to check the generated code. But it doesn't. It works fine in FxCop 1.35. It works fine when the offending code is not in a class with the CompilerGenerated attribute. The rule itself checks for code that constructs new ResourceManager objects. This happens in strongly typed resource classes when you use the default ResXFileCodeGenerator Custom Tool. If you change the Custom Tool to a different value you can generate different code (i.e. code that doesn't construct ResourceManager objects). My rule checks to see if the code uses a ResourceManager and therefore the Custom Tool setting is incorrect for my purposes. I would argue that it is valid to check for compiler generated code in this context because the generated code *can* be changed (by changing the Custom Tool).

     

    Can someone confirm if FxCop 1.36 is specifically ignoring code generated for .resx files and ignoring the "Suppress analysis results against generated code" setting ?

     

    Thanks.

     

    Guy

解答

  • 2008年7月29日 下午 10:58Haiying Xu - MSFTMSFT使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆

    There is two kinds of generated code: Tool generated code, with attribute [System.CodeDom.Compiler.GeneratedCode("ToolName", "1.1.1")], and compiler generated code, with attribute [System.Runtime.CompilerServices.CompilerGenerated()].

    In FxCop1.36. FxCop will always ignore Compiler Generated code ([System.Runtime.CompilerServices.CompilerGenerated()]). The suppress generated code is for tool generated code.

     

    Btw, why you are using CompilerGenerated instead of GeneratedCode? because it sounds like actually GeneratedCode.

     

    With thanks,

    Haiying

     

所有回覆

  • 2008年7月29日 下午 10:58Haiying Xu - MSFTMSFT使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆

    There is two kinds of generated code: Tool generated code, with attribute [System.CodeDom.Compiler.GeneratedCode("ToolName", "1.1.1")], and compiler generated code, with attribute [System.Runtime.CompilerServices.CompilerGenerated()].

    In FxCop1.36. FxCop will always ignore Compiler Generated code ([System.Runtime.CompilerServices.CompilerGenerated()]). The suppress generated code is for tool generated code.

     

    Btw, why you are using CompilerGenerated instead of GeneratedCode? because it sounds like actually GeneratedCode.

     

    With thanks,

    Haiying

     

  • 2009年4月14日 上午 11:55Guy Smith-FerrierMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Haiying,

    Thanks for the clarification.

    > FxCop will always ignore Compiler Generated code ([System.Runtime.CompilerServices.CompilerGenerated()]).

    Ok, so I am saying that this needs to be configurable because there are legitimate cases where FxCop must be able to analyze this code.

    > Btw, why you are using CompilerGenerated instead of GeneratedCode? because it sounds like actually GeneratedCode.

    It's not my code - it's Visual Studio's code. It comes from the ResXFileCodeGenerator (and others) that is used by Visual Studio to generate strongly typed resource classes. I need to be able to run FxCop rules over this code for the reasons given in my previous post.

    Could you make this change ?

    Thanks.

    Guy