davidwengier / SourceGeneratorTemplate

A basic template for writing a C# source generator
178 stars 30 forks source link

Internal NuGet dependency #6

Open magol opened 3 years ago

magol commented 3 years ago

Can you please update the code to show how do if the generator is dependent on a NuGet package. I think it is a common scenario.

I have try to use you template to write a generator that is generating code based on a json file using System.Text.Json, but I cannot make it to work. And how do I add the json file to the tests that you have in the template?

davidwengier commented 3 years ago

I can try to take a look, sure.

Did you see the guidance on NuGet dependencies in the cookbook? https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.cookbook.md#use-functionality-from-nuget-packages

Also since this project was created, there is now testing support for generators via roslyn-sdk which might be easier to use for some scenarios. A good repo example for that would be https://github.com/jmarolf/generator-start

magol commented 3 years ago

Thanks for your reply. Yes, I have seen the cookbook, but I still do not get it to work. The cookbook, and many other pages, are focused on creating a NuGet package of the generator. But I'm interested in that, I just want to use it to generate code in another project in the same solution.

I had not seen generator-start before, so it was interesting to review that code. But as soon as I added a dependency to System.Text.Json to that generator, I got the same problem as in my project. So it's obviously something I'm doing wrong.

Youssef1313 commented 2 years ago

There is some discussion about that in https://github.com/dotnet/docs/pull/28054.

tom-englert commented 2 years ago

Here is a sample project that covers the case with NuGet dependencies: https://github.com/tom-englert/LogMessageGenerator/