-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Refitter Source Generator - generated code not being picked up by Refit's Source Generator #100
Comments
Thanks for reporting @guillaumeserale the source generator has so far been an experiment that I started playing around with lately I cloned your example repo and updated the .csproj to this: <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Refit.HttpClientFactory" Version="7.0.0" />
<PackageReference Include="Refitter.SourceGenerator" Version="0.7.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<Target Name="ExcludeSourceGeneratedFiles" BeforeTargets="CoreCompile">
<ItemGroup>
<Compile Remove="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
</ItemGroup>
</Target>
<Target Name="IncludeSourceGeneratedFiles" AfterTargets="CoreCompile">
<ItemGroup>
<Compile Include="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
</ItemGroup>
</Target>
</Project> Which placed the generated files within the project and excludes the files right before compilation to avoid duplicate types. It looks like this in Visual Studio So the problem here is that I have honestly only really tested that the project output code builds, I don't think I have actually ran any project using the source generated code yet. You're absolutely right, it doesn't work to run the code at all! I just get this error
No idea how to fix this yet, or if its even possible to fix it, since I'm not sure how to chain these source generators or how to ensure that Refitter generates code before Refit generate codes This is definitely an interesting problem! I should probably deprecate the source generator NuGet for now and mark it as invisible |
@guillaumeserale I found a dirty workaround... <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Refit.HttpClientFactory" Version="7.0.0" />
<PackageReference Include="Refitter.SourceGenerator" Version="0.7.2" />
</ItemGroup>
<Target Name="ExcludeSourceGeneratedFiles" BeforeTargets="CoreCompile">
<ItemGroup>
<Compile Remove="$(CompilerGeneratedFilesOutputPath)/**/Refitter.SourceGenerators.RefitterSourceGenerator/*.cs" />
</ItemGroup>
</Target>
<Target Name="IncludeSourceGeneratedFiles" AfterTargets="CoreCompile">
<ItemGroup>
<Compile Include="$(CompilerGeneratedFilesOutputPath)/**/Refitter.SourceGenerators.RefitterSourceGenerator/*.cs" />
</ItemGroup>
</Target>
</Project> This will keep the Refit generated code and only exclude the Refitter generated code during compilation |
I deprecated all versions of the source generator in nuget.org and marked them to have critical issues thanks again for bringing this up @guillaumeserale I hope there's a solution to this |
@christianhelle Thanks for the detailed explanation and analysis. |
FYI: There's an open issue in Roslyn about the sequence order of Source Generators. |
What do you think of this experience @guillaumeserale ? The down side with this current source generator implementation is that you are required to commit the generated code to source control. On the hand, if you use the CLI Tool to generate code, then you are committing generated code to source control anyway |
@christianhelle I've played a bit with your latest change. Pretty clever 👍 I really wished the Roslyn team would have added some execution priority mechanism in the SourceGenerator. |
@guillaumeserale Yes, that was the best I could do for now 😅 |
When using the new Refitter Source Generator to generate Refit Interfaces and classes, the generated code is not being picked up by Refit's Source Generator:
This makes the Refitter Source Generator unusable for now.
Link to repo to reproduce the issue.
Any ideas on how to fix this ?
The text was updated successfully, but these errors were encountered: