✅ Getting started with source generators
Hi guys, I am currently trying create a source generator. So I startet with setting up a project to test source generators and try out some things.
It somewhat worked however the generated files seem to not be updating when I the code of the generator.
I tried dotnet clean and dotnet build but that didn't change anything. Rider shows the generated files properly however when I look in the dlls of the build output the generated files in there are still the same as before. I also had some issues building it at first but at some point it just worked, not quite sure why.
Today I tried to build the project again and it did change the generated files. Does anyone know what I am doing wrong or just how to properly setup a source generator project in general.
10 Replies
PS feel free to ping me in here
Can you give some more details?
about my project?
well I just followed the microsoft guide
https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview
Source Generators
Source Generators is a C# compiler feature that lets C# developers inspect user code as it is being compiled. Source generators create new C# source files on the fly that are added to the user's compilation.
Firstly (I'm sorry), don't follow that.
ISourceGenerator
is deprecated.yes I also saw that so after that I checked the examples from the IIncrementalGenerator from the roslyn github
https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.md
and tried some examples from there but same result
GitHub
roslyn/incremental-generators.md at main · dotnet/roslyn
The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs. - roslyn/incremental-generators.md at main · dotnet/roslyn
It is a very known and common issue that IDEs just... don't work with source generators. Rider not showing the updated files doesn't sound out of the question, it's likely that it's a bug in Rider rather than in issue with your generator.
If the files are properly generated when running
dotnet build
then everything works as intended™️, it's just the IDE integration which is trash.might be but I also tried via dotnet clean/build/run and same result
also Rider is showing the proper updated version of the generated code but it is just not in the build for some reason
huh, that's odd
Ask in #roslyn, you'll likely get better help there.
okay Ill do
thank you
okay someone In the #roslyn channel helped me
https://discord.com/channels/143867839282020352/598678594750775301/1112354437885861999
the solution was
dotnet build-server shutdown
after I did that I could rebuild the solution and get the updated generated files
I suppose this issue occurres because the compiler keeps the generator cached until it gets restated to save on compile timeAntonC#3545
try the command
dotnet build-server shutdown
Quoted by
<@!410486732933431298> from #roslyn (click here)
React with ❌ to remove this embed.