services.AddSwaggerGen()给出错误 [英] services.AddSwaggerGen() giving error

查看:1089
本文介绍了services.AddSwaggerGen()给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做的就是向ASP.Net Core应用程序添加招摇.我正在观看教程,我所看到的只是在Startup.cs文件的configure services区域下添加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()给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆