简体   繁体   English

.net 6.0:如何在 .net 6.0 中生成 Swagger.json 文件?

[英].net 6.0 : 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.我想在构建时生成 Swagger.Json 文件并在 API 网关中使用它来配置端点。

I have tried following steps but its not working.我已尝试执行以下步骤,但它不起作用。

Create a tool manifest:创建工具清单:

dotnet new tool-manifest

Install the Swashbuckle CLI tool and add it to the local manifest file: But this step fails安装Swashbuckle CLI工具,添加到本地manifest文件中:但是这一步失败

dotnet tool install --version 6.4.0 Swashbuckle.AspNetCore.Cli

Error:错误:

 NU1202: Package Swashbuckle.AspNetCore.Cli 6.4.0 is not compatible with net6.0 (.NETCoreApp,Version=v6.0). Package Swashbuckle.AspNetCore.Cli 6.4.0 supports:
  - net5.0 (.NETCoreApp,Version=v5.0) / any
  - net6.0 (.NETCoreApp,Version=v6.0) / any
  - netcoreapp2.1 (.NETCoreApp,Version=v2.1) / any
  - netcoreapp3.0 (.NETCoreApp,Version=v3.0) / any
NU1212: Invalid project-package combination for Swashbuckle.AspNetCore.Cli 6.4.0. DotnetToolReference project style can only contain references of the DotnetTool type 
NU1212: Invalid project-package combination for Swashbuckle.AspNetCore.Cli 6.4.0. DotnetToolReference project style can only contain references of the DotnetTool type 
Package 'Swashbuckle.AspNetCore.Cli 6.4.0' has a package type 'DotnetTool' that is not supported by project 'WebApi'.

Check below practice The idea works in requesting the swagger.json on execution.检查下面的实践这个想法在请求 swagger.json 执行时有效。

https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/541#issuecomment-358772489 https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/541#issuecomment-358772489

在此处输入图像描述

There is also another solution on the build, instead https://medium.com/@woeterman_94/how-to-generate-a-swagger-json-file-on-build-in-net-core-fa74eec3df1构建中还有另一个解决方案,而不是https://medium.com/@woeterman_94/how-to-generate-a-swagger-json-file-on-build-in-net-core-fa74eec3df1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM