首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用带有文档配置的aspnet-api版本控制库时出错

使用带有文档配置的aspnet-api版本控制库时出错
EN

Stack Overflow用户
提问于 2018-04-27 12:47:39
回答 1查看 1.1K关注 0票数 2

在我的web项目中,我正在使用aspnet版本库。我遵循https://github.com/Microsoft/aspnet-api-versioning/wiki/API-Documentation的指示。我添加了代码,正如在我的WebApiConfig.cs中解释的那样

所以

代码语言:javascript
复制
namespace Nppg.WebApi
{

using Microsoft.Web.Http.Versioning;
using Nppg.WebApi.ActionFilters;
using System.Web.Http;

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // Add specific Json converter/formetters
        var jsonFormatter = config.Formatters.JsonFormatter;
        jsonFormatter.SerializerSettings.Converters.Add(new LinkDtoConverter());

        // Web API configuration and services
        // Configure Web API to use only bearer token authentication.
        config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
        config.Filters.Add(new HttpLoggingFilterAttribute());
        config.MessageHandlers.Add(new LogRequestAndResponseHandler());

        #region API versioning configuration
        // allow a client to call you without specifying an api version
        // since we haven't configured it otherwise, the assumed api version will be 1.0
        // https://github.com/Microsoft/aspnet-api-versioning/wiki/New-Services-Quick-Start
        // added to the web api configuration in the application setup
        config.AddApiVersioning(options =>
        {
            options.ApiVersionReader = new MediaTypeApiVersionReader();
            options.AssumeDefaultVersionWhenUnspecified = true;
            options.ApiVersionSelector = new CurrentImplementationApiVersionSelector(options);
        });

        //This code must be used to register "apiVersion" as a contraint
        //var constraintResolver = new DefaultInlineConstraintResolver()
        //{
        //    ConstraintMap = { ["apiVersion"] = typeof(ApiVersionRouteConstraint) }
        //};

        // format the version as "'v'major[.minor][-status]"
        var apiExplorer = config.AddVersionedApiExplorer(o => o.GroupNameFormat = "'v'VVV");

        config.EnableSwagger(
            "{apiVersion}/swagger",
            swagger =>
            {
                swagger.MultipleApiVersions(
                    (apiDescription, version) => apiDescription.GetGroupName() == version,
                    info =>
                    {
                        foreach (var group in apiExplorer.ApiDescriptions)
                        {
                            info.Version(group.Name, $"Sample API {group.ApiVersion}");
                        }
                    });
            })
         .EnableSwaggerUi(swagger => swagger.EnableDiscoveryUrlSelector());



        #endregion

        // Web API routes
        //config.MapHttpAttributeRoutes(constraintResolver); // With URL Path Versioning
        config.MapHttpAttributeRoutes(); // Whithout URL Path Versioning

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }
}
}

我收到以下错误消息:

Error CS1061 'HttpConfiguration‘不包含'AddVersionedApiExplorer’的定义,也找不到接受'HttpConfiguration‘类型的第一个参数的扩展方法'AddVersionedApiExplorer’(您缺少使用指令还是程序集引用?)

Error CS1061 'HttpConfiguration‘不包含'EnableSwagger’的定义,也找不到接受'HttpConfiguration‘类型的第一个参数的扩展方法'EnableSwagger’(您缺少使用指令还是程序集引用?)

知道我为什么会收到这些信息吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-27 20:09:16

尝试在Microsoft.AspNet.WebApi.Versioning.ApiExplorer的这里上安装nuget软件包

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50062750

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档