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
Is that something that could be what you're looking for ?
Generate OpenAPI documents
Learn how to generate and customize OpenAPI documents in an ASP.NET Core app
@Pedro This doesn't explain the way to do it myself. Only how to tell swagger to do it.
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 ?
yes
And I want that file to be part of down stream build outputs that reference this project as well
as a class library not a nuget or something else
?
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>
I mean it will be in your class output, but you want it in the main project
it is a csv file
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 🙂
openapi does that for u
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•2mo ago
Message Not Public
Sign In & Join Server To View