使用Strawberry Shake未生成客户端问题咨询
Hey there! Let's walk through some common checks to figure out why your Strawberry Shake client isn't generating after building. I've hit this exact issue a few times before, so here's what I'd investigate step by step:
Double-check your project configuration
First, pop open your.csprojfile and make sure you've got the right Strawberry Shake packages and client setup. You should see something like this:<PackageReference Include="StrawberryShake.CodeGeneration.CSharp" Version="YOUR_VERSION" PrivateAssets="all" /> <PackageReference Include="StrawberryShake.Transport.Http" Version="YOUR_VERSION" /> <ItemGroup> <GraphQLClient Include="path/to/your/schema.graphql" Name="YourDesiredClientName" /> </ItemGroup>Confirm the
GraphQLCliententry points to your actual schema file, and theNameproperty is set (this will be part of your generated client class name). Missing or misconfigured entries here are the most common culprit.Dig into build logs for clues
Don't just rely on the "build succeeded" message. Run a detailed build withdotnet build -v detailed(or check Visual Studio's build log via Build > View Logs) and look for any warnings or errors tagged with Strawberry Shake. Sometimes the build passes but the code generation step fails silently—logs will tell you if there's a schema syntax issue, path problem, or generation error.Look in hidden folders
By default, Strawberry Shake dumps generated code into your project'sobj\Generateddirectory, which is usually hidden. Try enabling "Show hidden items" in File Explorer, or right-click your project in Visual Studio and select "Show All Files"—you might find the generated client sitting there all along.Clean and rebuild from scratch
Cached files inobjorbincan mess with generation. Rundotnet clean, delete both folders manually, then do a freshdotnet build. This wipes out any stale data that might be blocking the client from being generated.Validate your schema file
Even if you think the schema is good, double-check it for syntax errors. Use a tool like the GraphQL extension for VS Code to validate definitions—missing commas, invalid field types, or broken directives can cause the generator to fail without loud errors.Verify version compatibility
Make sure your Strawberry Shake package versions match your .NET runtime version. For example, if you're on .NET 7, use a recent Strawberry Shake release that supports it. Version mismatches can lead to silent generation failures.
内容的提问来源于stack exchange,提问作者Dotnetsqlcoder

