I am trying to move a lot of my runtime reflection stuff to AOT with the new Source Generators, however I am facing a few issues. Let me first talk through the requirements I have.
Now to a more visual example, imagine package A to be the NuGet library which should contain code for the user of the package A. Package B, the package containing the source generators which again should be executed on the users code-base and not on package A. Package B should be shipped with package A.
Why it is such a big deal to ship the Source Generator with the library? The SG's will produce code which is required for library itself.
I might have skipped something while reading through the docs, however I am just unable to figure it out, assuming this is even possible.
It actually turned out to be easier than expected. It is possible to ship the Source Generator in the same NuGet package by referencing it as an Analyzer with the PackagePath
argument in the .csproj file of the parent project.
<ItemGroup>
<None Include="Path\To\SourceGenerator\bin\$(Configuration)\netstandard2.0\NameOfSourceGenerator.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With