roslyn
roslyn copied to clipboard
Feature Request: Runtime only dependencies for source generators
Version Used: dotnet version 5.0.100
I have a source generator that is .net standard 2.0, but it generates .net standard 2.1 code.
I would like my generated code and thus the consumers of my Source Generator to have a dependency on a .net standard 2.1 nuget package.
The way to do this according to https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.cookbook.md is to take a public dependency on the nuget package, via a Package Reference in the Source Generator project.
I can't do that because a .net standard 2.0 project cannot reference a .net standard 2.1 package.
Currently you can do the following:
- Have a public dependency (both generator and consumer depend on the package)
- Private dependency (only the source generator depends on the package)
I'm proposing a third option:
- Runtime only dependency (only the consumer depends on the package)
This Package Reference would not need to be checked against the Source Generators version or project because the Source Generator doesn't use it, only the consumer of the Source Generator needs it.
I had this exact same problem with my .NET 5 runtime dependency
I have the same issue. I've got this open stack overflow question, which is a bit wandering, but I suspect everything would be fixed if the 2.0 to 2.1 mismatch worked.
I have the same issue, my source generator generates code that takes dependency on a nuget package. Currently, the consumer will need to add that package as well. Too bad this is still not fixed.
With ProjectReference
we have the option to not reference the output assembly but we don't have similar option with PackageReference
.
SourceGenerators just generate source. And, specifically, teh exact same source that a user could manually add. If you want the user to add a package reference, tell them to do so :)