I created a Source Generator to extend (partial) classes which fulfill certain criteria. To check and view the generated code I enabled the emission of these files by adding the following to my project:
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
This works as long as I don't do refactoring - like renaming a class. Because for every class a file is generated but not removed when I rename the "source" class.
So I added the following code to clean all generated files (on clean and rebuild)
<Target Name="CleanSourceGeneratedFiles" AfterTargets="Clean">
<RemoveDir Directories="Generated" />
</Target>
However then every second rebuild fails with:
Error CS2001 Source file 'xyz.generated.cs' could not be found.
So I'm looking for another way to keep my generated sources up to date, where the project not only compiles every second try.