EnableApiKeySupport 生成错误

EnableApiKeySupport generates error

尝试使用 Swashbuckle 添加不记名令牌时 swagger-document

我在 SwaggerConfig.cs 中遇到了这个错误 swaggeruiconfig 不包含 'EnableApiKeySupport'

的定义

有没有人知道可能是什么原因

更新

这是全部swagger.config

using System.Web.Http;
using WebActivatorEx;
using Swashbuckle.Application;

[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]

namespace AppNameSpace
{
public class SwaggerConfig
{
    public static void Register()
    {
        var thisAssembly = typeof(SwaggerConfig).Assembly;

        GlobalConfiguration.Configuration
            .EnableSwagger(c =>
                {
                    c.ApiKey("Token")
                     .Description("Filling bearer token here")
                     .Name("Authorization")
                     .In("header");

                    c.SingleApiVersion("v2", "AppNameSpace");

                    c.IncludeXmlComments(GetXmlCommentsPath());


                })
            .EnableSwaggerUi(c =>
                {
                    c.EnableApiKeySupport("Authorization", "header");


                });
    }
    protected static string GetXmlCommentsPath()
    {
        return System.String.Format(@"{0}\bin\AppNameSpace.XML", System.AppDomain.CurrentDomain.BaseDirectory);
    }
}

}

我相信这是你在 Swashbuckle 之外的项目中的一些东西,我用你的 GlobalConfiguration 创建了一个测试项目,它编译没有任何错误:
https://github.com/heldersepu/csharp-proj/tree/master/WebApi560

在该测试项目中,我使用了以下包:

<package id="Swashbuckle" version="5.6.0" targetFramework="net452" />
<package id="Swashbuckle.Core" version="5.6.0" targetFramework="net452" />
<package id="WebActivatorEx" version="2.0" targetFramework="net452" />



您可以尝试查看可用于 SwaggerUiConfig 的选项...
在您的 VisualStudio 项目中删除 EnableApiKeySupport 并让 IntelliSense 向您显示可用的内容,您应该会看到如下内容:

如果你的和我照片上的不一样。您可能会覆盖 class SwaggerUiConfig。