title: How to exclude auto generated files from getting analyzed from your custom code analysis rule?
body: <p>I have written a custom code analysis rule using FxCop sdk api and integrated it into my test project. It is correctly analyzing the project code, however it also analyses auto generated files. i.e in my case files generated having extension as '.g.i.cs'.</p>
  <p>I have tried checking the value for 'Suppress Code Analysis Errors in Generated Code' in my Code Analysis properties of my project. However there is no difference in my output.</p>
  <p>Can anyone tell me how can I exclude my auto generated code from getting analyzed with my custom rule ?</p>
  <p>EDIT :
  After spending some more time analyzing the issue and implementation I came to a conclusion that the auto generated code is getting analyzed due to the absence of <code>[GeneratedCodeAttribute]</code> on some fields in the auto generated <code>.g.i.cs</code> files.</p>
  <p>Here's a sample of my auto generated code:</p>
  <pre><code>#line 72 &quot;..\..\..\..\Views\Screen.xaml&quot;
  [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute(&quot;Microsoft.Performance&quot;, &quot;CA1823:AvoidUnusedPrivateFields&quot;)]
  internal System.Windows.Controls.TextBlock txtCopyright;
  
  #line default
  #line hidden
  
  /// &lt;summary&gt;
  /// InitializeComponent
  /// &lt;/summary&gt;
  [System.Diagnostics.DebuggerNonUserCodeAttribute()]
  [System.CodeDom.Compiler.GeneratedCodeAttribute(&quot;PresentationBuildTasks&quot;, &quot;4.0.0.0&quot;)]
  public void InitializeComponent() {
      if (_contentLoaded) {
          return;
      }
      _contentLoaded = true;
      
      #line default
      #line hidden
  }
  </code></pre>
  <p>In this sample, the field <code>txtCopyright</code> is analyzed during code analysis and the method <code>InitializeComponent()</code> is skipped, respective to the presence of <code>[GeneratedCodeAttribute]</code>.</p>
  <p>I found a solution to this by having a partial class with same name as auto generated file and then adding a <code>[GeneratedCodeAttribute]</code> on top of that class.
  But this doesn't seems right as it may skip some code that should be actually analyzed.</p>
  <p>Can anyone help me know what can be done to exclude fields like <code>txtCopyright</code> be skipped during code analysis of code ?</p>