How to ship a .Net library with an included source generator?
Asked Answered
T

1

7

I can't figure out how to ship a .Net library that also includes a Roslyn source generator, and have the source generator access the source code of the main project, without adding an explicit reference from the main project to the generator.

Presently, my source generator only sees the source code of my lib, but not the source code of the main calling project.

Here is how I set up my project:

User "console" test project -> project dependency on -> My lib -> project dependency on -> My source generator

My lib and my source generator are distributed together and I wanted for the user to reference the lib but not have to worry about setting up the source generator as well.

Tabitha answered 24/8, 2021 at 4:7 Comment(0)
A
6

To do this you should distribute your library and source generator as a single NuGet package, and you embed the generator as an analyzer. This documentation gives a bit of an example of how to make the NuGet package for just a generator. That way when the user installs the NuGet package they'll get both references at once.

Arlettearley answered 26/8, 2021 at 22:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.