【发布时间】:2019-10-23 11:10:40
【问题描述】:
我是否因为我的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>
【问题讨论】:
-
请上传您的
csproj文件或列出您的PackageReference -
我已经添加了我的 .csproj
-
一切似乎都很好,恐怕我对此一无所知:|
-
尝试将其更改为
c.SwaggerDoc("v1", new OpenApiInfo{ Title = "My API", Version = "v1" });
标签: c# asp.net-core swagger