'SwaggerGenOptions' 不包含 'SerializeAsV2' 的定义

'SwaggerGenOptions' does not contain a definition for 'SerializeAsV2'

我正在尝试使用 swaggergen 工具,所以我配置了我的服务:

        services.AddSwaggerGen(c =>
        {
            c.SerializeAsV2 = true;
            c.CustomOperationIds(apiDescription => {
                return apiDescription.TryGetMethodInfo(out MethodInfo methodInfo) ? methodInfo.Name : null;
            });

我的 nuget 包管理器中安装了 Swashbuckle.AspNetCore 和 Swashbuckle.AspNetCore.Newtonsoft

为什么 c.SerializeAsV2 有一个红色的波浪形:“'SwaggerGenOptions' 不包含 'SerializeAsV2' 的定义”我在 google 中根本找不到任何相关内容.

将其移动到 Configure 方法:

app.UseSwagger(c =>
{
    c.SerializeAsV2 = true;
});

参考:Serialize Swagger in the 2.0 format