C
C#•2mo ago
Pikachu

How does the generated swagger.json file get included in build output?

I am trying something where a script runs to create a file and I want it swept as part of the build process? Just placing it in the output folder ($OutDir) doesn't do the trick for dependent projects. Basically I want to include a file I generate as part of the build artifacts but I am not sure how to. Swagger seems to do this where the generated file has the "Build Action" as "Content" and "Copy To Output Directory" as "Copy If Newer".
13 Replies
Pedro
Pedro•2mo ago
Is that something that could be what you're looking for ?
Pikachu
PikachuOP•2mo ago
@Pedro This doesn't explain the way to do it myself. Only how to tell swagger to do it.
Pedro
Pedro•2mo ago
Oh okay, I saw the swagger.json things and assumed it was revolving around swagger. You just want to know how to ouput a file to your build output basically, right ?
Pikachu
PikachuOP•2mo ago
yes And I want that file to be part of down stream build outputs that reference this project as well
Pedro
Pedro•2mo ago
as a class library not a nuget or something else ?
Pikachu
PikachuOP•2mo ago
It is a file that I am creating as part of a post build event like this <Target Name="PostBuild" AfterTargets="Build"> <!-- Post-build tasks --> </Target>
Pedro
Pedro•2mo ago
I mean it will be in your class output, but you want it in the main project
Pikachu
PikachuOP•2mo ago
it is a csv file
Pedro
Pedro•2mo ago
You're reaching what I get, can do here ^^ I'm not fully getting the full problem and have to go. Hope someone will be more usefull than me 🙂
whatsinaname
whatsinaname•2mo ago
openapi does that for u
whatsinaname
whatsinaname•2mo ago
public static void SaveSwaggerJson(this IServiceProvider provider) { ISwaggerProvider sw = provider.GetRequiredService<ISwaggerProvider>(); OpenApiDocument doc = sw.GetSwagger("v1", null, "/"); string swaggerFile = doc.SerializeAsJson(Microsoft.OpenApi.OpenApiSpecVersion.OpenApi3_0); File.WriteAllText("swaggerfile.json", swaggerFile); } program.cs or startup file app.Services.SaveSwaggerJson(); https://stackoverflow.com/questions/73655243/how-to-generate-swagger-json-file-on-build-in-net-6-0
Stack Overflow
How to generate Swagger.json file on build in .net 6.0?
I want to generate Swagger.Json file on build and use it in API gateway to configure the endpoints. I have tried following steps but its not working. Create a tool manifest: dotnet new tool-manifest
Unknown User
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?