Asp.net core 在Azure Web API中调用UseSwagger时出错
我已经创建了VS2015和.Net核心Web API项目。 我在下面的例子中 我已经安装了Swashback.AspNetCore,下一步尝试编码,但在使用UseSwagger时出错。请告诉我Asp.net core 在Azure Web API中调用UseSwagger时出错,asp.net-core,asp.net-web-api2,swagger-ui,Asp.net Core,Asp.net Web Api2,Swagger Ui,我已经创建了VS2015和.Net核心Web API项目。 我在下面的例子中 我已经安装了Swashback.AspNetCore,下一步尝试编码,但在使用UseSwagger时出错。请告诉我 /* Startup.cs */ using System; using System.Collections.Generic; using System.Linq; using Microsoft.Owin; using Owin; using Swashbuckle.AspNetC
/* 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" });
});
}
}
}
我根据您的代码假设您正在使用.Net Core 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($@"{0}\bin\MyApi.XML",
System.AppDomain.CurrentDomain.BaseDirectory);
}