Open ghost opened 3 years ago
@ovargasmahisoft were you trying to add the attribute code using context.RegisterForPostInitialization
as the AutoNotify sample does? If so that's only supported in VS16.9+
Hi @chsienki thanks for your response.
Yes I tried that way and the code builds and runs fine but the IDE doesn't recognize it, it is ok if this is a IDE issue for now. What I find weird, is that even the HelloWorld sample fails to recognize the code just after registering a SyntaxReceiver.
when I register a SyntaxReceiver in the Initialize method
You definitely don't want to do this. There is no way to use RegisterForSyntaxNotifications
from the V1 API without causing an overwhelming performance hit for anything but the smallest of solutions. For syntax callbacks, you'll want to rewrite the source generator using IIncrementalGenerator
which was added in Roslyn 4.0 and resolves this problem.
We tried hard to find viable workarounds that allow SyntaxReceiver
to work without problems, but were never successful.
Hi,
I hope this is the right repository to report the this issue.
I'm doing some test with code generator for a new project, I'm following the samples here:
https://github.com/dotnet/roslyn-sdk/tree/main/samples/CSharp/SourceGenerators/SourceGeneratorSamples
I saw in the documentation that Roslyn apparently works only for Visual Studio, nevertheless, I tried with Rider 2020.3 on my Mac, and I found that it works pretty fine.
In Rider the code looks broken before the first build, but after building the solution looks perfect as if the code were defined in the project, I can see the generated code.
The weird behavior occurs when I register a SyntaxReceiver in the Initialize method, the build still pass and the code is executed, but neither Rider nor in Visual Studio for Mac recognize the generated code.
This is my
Target
projectThis is the Source project
This generated code work perfect
This is the code with the problem
I moved the Attribute code to the Execute method to make it work, because adding the code through the Initialize method has the same weird behavior.
I'm not sure if this is a bug or I'm missing something in my code.