Source Generator creates files but no dependency is added #80818
Unanswered
lucanatalidg
asked this question in
Q&A
Replies: 1 comment
-
This is what I would expect. Generators do not see files from dependencies; they only see symbols. You need to reference the generator from where the types you want to use in the generator are defined. I'm guessing that |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I’m having an issue that I’ll try to explain as clearly as possible.
I’ve created an
IIncrementalGeneratorproject (Mapper) that looks for files starting with "MapConfig" in referencing projects.For example, a file named
MapConfigTestApi.cscontains the following mapping definitions:The TestApi project references the
Mapperproject like this:<ProjectReference Include="..\mapper\mapper.csproj" OutputItemType="Analyzer" />Here are the class definitions:
Now, the issue I’m facing is this:
When the class definitions are inside the TestApi project, everything works fine.
The generated files appear under:
Dependencies → Analyzers → mapper → MapperGenerator.MapToGenerator → SimpleAddress_Map_SimpleAddressDto.g.cs
and
SimpleClass_Map_SimpleClassDto.g.cs.
However, if I move these classes into another project (e.g. ModelLibrary) that TestApi references, then no dependency is added to TestApi project.
But, if I add the following line to
TestApi.csproj:I can see all the generated files there, and they are correct!
Additionally, if I remove the nested class (so that
SimpleClassno longer contains theSimpleAddressproperty), everything works — even when the classes are declared in another project.Just another thing, as workaround, if I add this line to
TestApi.csprojgenerated files are added to the project and everything works... but it is not the same thing :-/
Could you please help me understand why these files are not added as dependencies when the class definitions are located in a different project?
Many thanks! 🙏
Luca
Beta Was this translation helpful? Give feedback.
All reactions