title: C# Source Generators Remove Files Before Build
body: <p>I am working a source generator that produces utility classes I am expecting other devs to use. I have the generator working perfectly. My issue is with emitting files to disk. I can emit the files to disk by</p>
  <pre><code>    &lt;PropertyGroup&gt;
           &lt;!--Persist the source generator (and other) files to disk--&gt; 
          &lt;EmitCompilerGeneratedFiles&gt;true&lt;/EmitCompilerGeneratedFiles&gt;
           &lt;!-- The &quot;base&quot; path for the source generators--&gt; 
          &lt;GeneratedFolder&gt;Generated&lt;/GeneratedFolder&gt;
           &lt;!-- Write the output for each target framework to a different sub-folder--&gt; 
          &lt;CompilerGeneratedFilesOutputPath&gt;$(GeneratedFolder)\$(TargetFramework)&lt;/CompilerGeneratedFilesOutputPath&gt;
      &lt;/PropertyGroup&gt;
  </code></pre>
  <p>The Above works out great. However, you cannot run the generator again b/c the types have already been defined.</p>
  <p>An easy work around for this is to remove the generated types from compilation. This is not desired because the devs will loose intellicents.</p>
  <p>The next option would be to remove the Generated dir during pre build.</p>
  <pre><code>    &lt;Target Name=&quot;CleanSourceGeneratedFiles&quot; BeforeTargets=&quot;BeforeBuild&quot; DependsOnTargets=&quot;$(BeforeBuildDependsOn)&quot;&gt;
          &lt;RemoveDir Directories=&quot;Generated&quot; /&gt;
      &lt;/Target&gt;
  </code></pre>
  <p>This does work except every other build now fails due to missing files.
  <br />
  <br />
  You cannot delete the generated files and regenerate them during the source generator due to the symbols already being loaded.
  <br />
  <br />
  How can I create a source generator that emits files to disk and give developers intellicents?</p>