Search code examples
c#visual-studio-2010stylecopgenerated-code

When I use WinForms (C#) designer in VS2010, it still generates code that StyleCop complains about


Some problems that I recall (there may be more):

  1. Includes regions
  2. Does not use this. prefix for member variables and methods
  3. Includes comments like the one below ( having // by itself catches the eye of StyleCop)

    //
    // fileNameTextBox
    // 
    

If I make a change to the text, and then open the designer again, and screws up my previously perfected fruits of hard labor. How did / would you solve this problem?

I heard but did not personally experience a similar problem with WPF. How did / would you fix that?

Thanks.


Solution

  • There are several ways to make StyleCop ignore generated code:
    StyleCop: How To Ignore Generated Code

    As I recall it, ignoring generated code is the default setting (at least, it ignores my VS 2008 generated code with the standard settings).

    I don't use VS 2010, so I don't know if they changed the designer generated files somehow so that StyleCop doesn't recognize them as generated anymore.
    Maybe the link helps you to figure that out in your code.