Skip to content
New issue

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

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

Already on GitHub? # to your account

How to Use AutoSDK as source generator #46

Closed
LittleLittleCloud opened this issue Sep 16, 2024 · 3 comments
Closed

How to Use AutoSDK as source generator #46

LittleLittleCloud opened this issue Sep 16, 2024 · 3 comments

Comments

@LittleLittleCloud
Copy link

This is how I refer AutoSDK from my .csproj file

  <PropertyGroup>
    <TargetFrameworks>net6.0;net8.0</TargetFrameworks>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <NoWarn>$(NoWarn);CS1591;CS1573</NoWarn>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AutoSDK" Version="0.24.0" />
  </ItemGroup>

<ItemGroup Label="AutoSDK">
  <AdditionalFiles Include="openapi.yaml" />
</ItemGroup>

<PropertyGroup Label="AutoSDK">
  <AutoSDK_Namespace>WebAPI.Generated</AutoSDK_Namespace>
  <AutoSDK_ClassName>OpenAI</AutoSDK_ClassName>
</PropertyGroup>

And I expected to see WebAPI.Generated.OpenAI get generated from AutoSDK, but found nothing in analyzer node.

Do I need any extra setup before using AutoSDK as source generator?

@HavenDV
Copy link
Collaborator

HavenDV commented Sep 17, 2024

You need to use

<PackageReference Include="AutoSDK.SourceGenerators" Version="0.24.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

instead

    <PackageReference Include="AutoSDK" Version="0.24.0" />

@LittleLittleCloud
Copy link
Author

Thanks @HavenDV , The source generator is corrected added by updating the reference package to AutoSDK.SourceGenerators. It successfully generate source code when I compile from dotnet cli. However, it fails to generate code in VS. I feel like it's more likely to be a bug on VS side and I created an issue for this bug in dotnet runtime repo. If you are also interested in details information, here is the link: dotnet/runtime#108164.

@HavenDV
Copy link
Collaborator

HavenDV commented Sep 17, 2024

Please also try to use latest dev version

Sometimes this problem can also go away if you clear the obj/bin directories, completely close VS, rebuild the project in different orders :)

I think it's issue on my side, recently I renamed project but don't test well source generation way

I checked the possible problem(missing files in nuget package) and it was not confirmed, so I recommend just trying the solution above
image

@HavenDV HavenDV closed this as completed Sep 22, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants