为什么找不到方法 app.UseSwaggerUI(...)?

Why the metod app.UseSwaggerUI(...) is not found?

我想在使用 .Net Core 3.1 创建的新 Web 应用程序中添加 swagger。我在以下行收到错误:

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});

'IApplicationBuilder' does not contain a definition for 'UseSwaggerUI' and no accessible extension method 'UseSwaggerUI' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

尽管我已经像 the MSDN example 那样安装了 Swagger。

这是来自NuGet的swagger包内容:

我有以下用途:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;

我错过了什么?

NuGeT 包 Swashbuckle.AspNetCore.Swagger 仅提供文档的 JSON 端点。

要真正拥有 UI,您还必须安装相应的包 Swashbuckle.AspNetCore.SwaggerUi

Install-Package Swashbuckle.AspNetCore.SwaggerUi -Version 5.6.3