Problem configuring incremental source generator nuget #75948
Unanswered
bjornhellander
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
I am trying to write a source generator and have some problems with how to set it up correctly.
Generally speaking, it feels like source generators should be development dependencies, right? If project A references a generator and project B references project A, then I don't want the generator running in project B as well. And I do not want the generator assembly to be included in the output of the library/application that uses the generator. This would make me add true in the generator csproj. But I do notice that the cookbook does not mention this at all, so maybe I am misunderstanding things.
The generated code uses types from another nuget (lets call it the support package), so I would like the consumers to automatically reference the matching version of that nuget just by referencing the generator. This would make me add a normal PackageReference in the generator project, just like the cookbook says here: https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.cookbook.md#use-functionality-from-nuget-packages.
My problem is that I can't seem to reconsile these two "requirements". If I do like I have described above, then I see the support package listed as a transitive dependency in the package manager, but the generated code does not compile, giving errors indicating that the support package is not really included in the compilation. Doesn't surprise me that much, since I have marked the generator as a development dependency. If I add it as a direct dependency in the consuming project, then it starts compiling.
I could remove the support package and generate the needed code from the source generator, but I would like to avoid doing that, since the generator is likely to be used in multiple projects in a given product.
I am doing something wrong/unreasonable? Is it possible to accomplish what I have described, ideally without pushing responsibilities on to the consumers of this generator?
Beta Was this translation helpful? Give feedback.
All reactions