[英]'Info' class not recognized with Swashbuckle and Swagger libraries
我是否缺少包或参考,因为我的AddSwaggerGen
方法无法编译。 我的代码:
我using Swashbuckle.AspNetCore.Swagger;
但是这段代码
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
c.EnableAnnotations();
});
不会编译:
错误 CS0246 找不到类型或命名空间名称“Info”(您是否缺少 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>
版本 5 中已弃用Info
它已被OpenApiInfo
取代,因此您必须在您的招摇设置中反映这一点:
c.SwaggerDoc("v1", new OpenApiInfo { Version = "1.0", Title = "My API" });
将 Info 类更改为 OpenApiInfo 类。
使用 Microsoft.OpenApi.Models 添加
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.