因为我的AddSwaggerGen
方法没有编译,所以缺少包或引用吗?我的代码:
我添加了using Swashbuckle.AspNetCore.Swagger;
但这段代码
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
c.EnableAnnotations();
});
将不编译:
错误CS0246无法找到类型或命名空间名称'Info‘(您是缺少使用指令还是程序集引用?)这是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>
发布于 2019-12-16 08:51:00
在版本5中不推荐使用Info
它已经被OpenApiInfo
所取代,所以您必须在您的傲慢的设置中反映这一点:
c.SwaggerDoc("v1", new OpenApiInfo { Version = "1.0", Title = "My API" });
发布于 2019-10-06 00:24:47
将Info类更改为OpenApiInfo类。
使用Microsoft.OpenApi.Models添加
https://stackoverflow.com/questions/56502869
复制相似问题