dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.04k stars 4.03k forks source link

Allow Source Generation based on down stream project references #75703

Open ThomasHeijtink opened 3 days ago

ThomasHeijtink commented 3 days ago

Since building a project also kicks-off and awaits for building referenced and transitive projects. Wouldn't it make sense to also allow source generators to have access to the syntax of down stream projects as well? Or at least make it configurable from the host/target project which of the down stream projects you want to include as source projects. Or allow the source generator to filter projects based on certain expressions.

For example, we have code in our domain layer for which we want to generate code in our application layer. This seems not to be possible with the out-of-the-box design and probably would require custom tooling and/or build actions to achieve this.

CyrusNajmabadi commented 3 days ago

There is no way to pass this information along. The product of one compilation is a dll, and it's only that dll that is passed to the downstream compilation.

Note that that dll may not even include IL (it may just be metadata in the case of a ref assembly). So all you have are the types and members signatures to work off of.

ThomasHeijtink commented 3 days ago

Yes, you told me. But that doesn't mean it can't be made possible.

Maybe it wasn't clear that this is a feature request.

After building one project, MSBuild could keep it in memory and pass it to the next project it builds, right?