tryAGI / AutoSDK

Automated .NET SDKs for your APIs
https://autosdk.net
Other
15 stars 2 forks source link

How to Use AutoSDK as source generator #46

Closed LittleLittleCloud closed 3 weeks ago

LittleLittleCloud commented 3 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

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: https://github.com/dotnet/runtime/issues/108164.

HavenDV commented 3 weeks ago

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