title: How to disable compiler warnings in only generated code without editing file(s)
body: <p>I have some generated code that has a bunch of compiler warnings. I want to disable them in the generated file, but keep those warnings in the rest of the project so they can be fixed. I'm using Visual Studio 2019 Community Edition, with the generated files coming from Entity Framework and other NuGet packages.</p>
  <p>I want to do this without changing the files, so I won't get the warnings back if they get regenerated. I also don't want to disable the warnings project wide, since they are normally useful warnings. I also don't want to edit the NuGet packages, since that would either require not upgrading them as newer releases are available or possibly having to make changes to the new version.</p>
  <p>I've already done plenty of reading, but evidently posting the links is &quot;too much&quot;, so I've removed them. Look in the edit history if you want to see them.</p>
  <p>The file in question is a <code>Reference.cs</code> for a Connected Service. It has the namespace of <code>Proxy.ProvisioningService</code> and this one file contains a couple of dozen classes. I also have a couple of Entity Framework migration files that have the same problem in a completely different solution.</p>
  <p>I have a GlobalSuppressions.cs file that I'd like to add the CS1591 (specifically) to, but my current entry isn't working. Other entries work for other warnings and I've tried variations of the below code to work, including trying to match the format of the other entries, but nothing is working so far. I've changed the &quot;Build&quot; from &quot;Compile&quot;, removed the <code>MessageId</code>, changed <code>Scope</code> to be &quot;module&quot;, &quot;assembly&quot;, and &quot;namespaceanddescendants&quot;, and I've tried a couple different ways to set the <code>Target</code>.</p>
  <pre><code>[assembly: SuppressMessage(&quot;Build&quot;, &quot;CS1591:Missing XML comment for publicly visible type or member&quot;, Justification = &quot;Generated code&quot;, MessageId = &quot;CS1591&quot;, Scope = &quot;namespaceanddescendants&quot;, Target = &quot;Proxy.ProvisioningService&quot;)]
  </code></pre>
  <p>In one of the off-site links, it suggests that I right-click the error, go to <code>Suppress -&gt; In Suppression File</code>, but that's not a listed option. Is that a clue that I can't do it in the <code>GlobalSuppressions.cs</code> file?</p>
  <p>I've tried to have Visual Studio 2019 Community Edition automatically suppress the warning by the menu item <code>Analyze -&gt; Build And Suppress Active Issues -&gt; For Project</code>, but that just added a bunch of <code>#pragma</code> directives to the file, which would have to be replaced if the file was regenerated, which I want to avoid.</p>
  <p>One of the linked answers suggested writing a script to add the <code>#pragma</code> directives on compile, but that script seems like a hack to me. I'd rather just not edit the generated code at all.</p>
  <p>I also don't want to put it in the <code>Project -&gt; Properties -&gt; Build -&gt; Suppress Warnings</code> section, since I want the hand written code to still throw these warnings.</p>
  <p>Another SE/SO answer suggests using the <code>GeneratedCodeAttribute</code> attribute to prevent warning from generated files. Unfortunately, my file already has this and it's still throwing the warnings.</p>
  <p>Another suggestion was to turn off warnings for these generated files:</p>
  <blockquote>
  <p>To suppress warnings for generated code in a project</p>
  <ol>
  <li><p>Right-click the project in Solution Explorer and then click Properties.</p>
  </li>
  <li><p>Choose the Code Analysis tab.</p>
  </li>
  <li><p>Select the Suppress results from generated code check box.</p>
  </li>
  </ol>
  </blockquote>
  <p>Unfortunately, this option is already selected and not suppressing the CS1591 warning.</p>
  <h2>So my actual question is:</h2>
  <p>How can I suppress warnings, specifically CS1591, from generated code files without editing them and without suppressing the warning throughout the whole project?</p>