Swashbuckle 和 Swagger 库无法识别“信息”类

use*_*146 8 c# swagger asp.net-core

我是否缺少包或参考,因为我的AddSwaggerGen方法无法编译。我的代码:

我加了 using Swashbuckle.AspNetCore.Swagger;

但是这个代码

  services.AddSwaggerGen(c =>
   {
     c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });                 
     c.EnableAnnotations();    
   });
Run Code Online (Sandbox Code Playgroud)

不会编译:

错误 CS0246 找不到类型或命名空间名称“信息”(您是否缺少 using 指令或程序集引用?)这是 csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>full</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DebugType>full</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="IdentityModel" Version="3.10.6" />
    <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-18618-05">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.0.0-rc2" />
    <PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.0.0-rc2" />
    <PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.0.0-rc2" />
    <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0-rc2" />
  </ItemGroup>
Run Code Online (Sandbox Code Playgroud)

小智 23

Info 在第 5 版中已弃用

它已被替换为,OpenApiInfo因此您必须在您的 swagger 设置中反映出来:

c.SwaggerDoc("My_Api", new OpenApiInfo { Version = "1.0", Description = "my api " });
Run Code Online (Sandbox Code Playgroud)


小智 7

将 Info 类更改为 OpenApiInfo 类。

添加使用 Microsoft.OpenApi.Models