Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Do not emit generated code if no Refit interfaces #1075

Closed
martincostello opened this issue Feb 11, 2021 · 2 comments · Fixed by #1076
Closed

feature: Do not emit generated code if no Refit interfaces #1075

martincostello opened this issue Feb 11, 2021 · 2 comments · Fixed by #1076
Assignees
Labels

Comments

@martincostello
Copy link
Contributor

Is your feature request related to a problem? Please describe.

As part of investigating coverlet-coverage/coverlet#1084 and the impact it is having on various projects I maintain trying to use Refit 6.0, I noticed that Refit is emitting a Generated class into each project that references Refit, even transitively, rather than only projects which explicitly define a Refit interface.

As a consequence this spreads the coverlet issue to the entire solution through the transitive reference(s) and breaks coverlet code coverage for all projects under test that reference Refit.

Unless there's a specific reason why this emitted code must always be present, it seems to me that it would be better not to emit the Generated class (or PreserveAttribute). As well as helping mitigate the problem in coverlet, it would also reduce the on-disk size of assemblies referencing Refit by not emitting unused types.

Would you accept a PR to adjust the generator in this way?

Describe the solution you'd like

Refit does not emit any generated code into an assembly referencing Refit if no Refit interfaces are present to generate code for.

Describe alternatives you've considered

None.

Describe suggestions on how to achieve the feature

Have the GenerateInterfaceStubs() method exit early if there are no Refit interfaces found.

public void GenerateInterfaceStubs(GeneratorExecutionContext context)

Additional context

Screenshot of ILSpy showing a Generated class in three assemblies, where two are empty, despite only one containing a Refit interface.

The assemblies were generated from this repro project: https://github.com/martincostello/coverlet-refit-repro

image

@clairernovotny
Copy link
Member

Totally valid -- we shouldn't be emitting code into projects where there aren't any interfaces.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants