2017-06-20 17 views
0

VS2015と.Net Core Web APIプロジェクトが作成されました。 私は次の例に従っていますhttp://www.technicalblogs.sentientmindz.com/2017/04/09/enabling-swagger-support-to-the-web-api/Azure Web APIでUseSwaggerを呼び出すときのエラー

私はSwashbuckle.AspNetCoreをインストールし、次にコードを作成しようとしましたが、UseSwaggerを使用するとエラーが発生します。私に助言してください。

/* Startup.cs */ 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using Microsoft.Owin; 
using Owin; 
using Swashbuckle.AspNetCore.Swagger; 
using Microsoft.Extensions.DependencyInjection; 

[assembly: OwinStartup(typeof(TestApi.Startup))] 

namespace TestApi 
{ 
    public partial class Startup 
    { 
     public void Configuration(IAppBuilder app) 
     { 
     ConfigureAuth(app); 

     /*use swagger added by me*/ 
     app.UseSwagger();  /*ERROR:iAppBuilder does not contain definition for UseSwagger…*/ 
     app.UseSwaggerUI(c =>. /*ERROR :iAppBuilder does not contain definition for UseSwaggerUI…*/ 
     { 
      c.SwaggerEndpoint("/swagger/v1/swagger.json", "Accounts API V1"); 
     }); 

    } 

    //Add framework services by me 
    public void ConfigureServices(IServiceCollection services) { 
     services.AddSwaggerGen(c => 
     { 
      c.SwaggerDoc("v1", new Info { Title = "AcccountsAPI", Version = "v1" }); 
     }); 

     } 
    } 
} 

答えて

0

私はこれは私がそれをやった方法です、あなたはネットコアV1.1を使用しているコードからと仮定しています:

public void Configuration(IAppBuilder app) 
    { 
     HttpConfiguration config = new HttpConfiguration(); 
     WebApiConfig.Register(config); 
     config.EnableSwagger(c => 
     { 
      c.SingleApiVersion("v1", "WebAPI"); 
      c.IncludeXmlComments(GetXmlCommentsPath()); 
      c.ResolveConflictingActions(x => x.First()); 

     }).EnableSwaggerUi(); 
    } 

    protected static string GetXmlCommentsPath() 
    { 
     return System.String.Format([email protected]"{0}\bin\MyApi.XML", 
       System.AppDomain.CurrentDomain.BaseDirectory); 
    } 
関連する問題