services.AddSwaggerGen() giving error(services.AddSwaggerGen() 给出错误)
问题描述
我想要做的只是将 swagger 添加到 ASP.Net Core 应用程序中.我正在看一个教程,我看到他们所做的只是在 Startup.cs 文件的配置服务区域下添加 services.AddSwaggerGen();.像 MVC 之类的任何普通服务一样......但我收到一个错误:
All I'm trying to do is add swagger to an ASP.Net Core application. I'm watching a tutorial and all I see them do is add services.AddSwaggerGen(); under the configure services area in the Startup.cs file. Like any normal service like MVC... But I get an error:
没有给出与所需形式参数setupAction"相对应的参数...
There is no argument given that corresponds to the required formal parameter 'setupAction'...
我没有看到任何人向 services.AddSwaggerGen() 提供任何类型的参数,所以有人知道我在这里缺少什么吗?
I don't see anyone supplying any kind of argument to services.AddSwaggerGen() so does anyone know what I'm missing here?
我已经添加了 SwashBuckler.AspNetCore 依赖项,因此应用程序中出现了招摇.只是不知道为什么它是红色的并给出上述错误.
I've added the SwashBuckler.AspNetCore dependency so swagger is in the application. Just don't know why it's red and giving the above error.
推荐答案
我有问题,那个
IServiceCollection 不包含AddSwaggerGen"的定义
IServiceCollection does not contain a definition for 'AddSwaggerGen'
事实证明,我安装了 Swashbuckle.AspNetCore.Swagger nuget 包而不是 Swashbuckle.AspNetCore.
I turnes out, that I installed Swashbuckle.AspNetCore.Swagger nuget package instead of Swashbuckle.AspNetCore.
在 .NET Core 3 中,此处讨论了一些问题.解决方案是在项目文件中添加以下内容,替换之前的版本.
In .NET Core 3, there's some issues as discussed here. The solution is to add the following to the project file, replacing the prior version.
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0-rc2" />
这篇关于services.AddSwaggerGen() 给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:services.AddSwaggerGen() 给出错误
基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
