dotnet / roslyn-sdk

Roslyn-SDK templates and Syntax Visualizer
MIT License
512 stars 257 forks source link

Add Source Generator to Compilation from NuGet Package #1096

Open HavenDV opened 1 year ago

HavenDV commented 1 year ago

For now, I'm using the Microsoft.CodeAnalysis.Testing and ReferenceAssemblies class to resolve packages and add them to Compilation. But this does not work for packages that contain source code generators. Is there a way to add source code generators from a NuGet package using Roslyn or Testing packages?

HavenDV commented 1 year ago

I guess I need to re-extract the NuGet archives myself, check the analyzers folder for dlls, open them, extract all generator classes, and use CSharpGeneratorDriver to update Compilation. I just want to make sure it's not already implemented

Youssef1313 commented 1 year ago

Should the generator added from NuGet package contribute to the expected generated sources? If yes, it will be quite breaking. Maybe a flag should be added along with this? In this case, this will be a sufficient solution for https://github.com/dotnet/roslyn-sdk/issues/1087 as well.