Asp.Net Core 项目搭建- Swager
1.安装Nuget包
Install-Package Swashbuckle.AspNetCore
2.修改Startup文件
using Microsoft.Extensions.PlatformAbstractions; using Swashbuckle.AspNetCore.Swagger; public void ConfigureServices(IServiceCollection services) {
services.AddMvc(); services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Info { Version = "v1", Title = "Demo Api" }); //Determine base path for the application. var basePath = PlatformServices.Default.Application.ApplicationBasePath; //Set the comments path for the swagger json and ui. var xmlPath = Path.Combine(basePath, "Web.Host.xml"); options.IncludeXmlComments(xmlPath); }); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "TwBusManagement API V1"); }); app.UseMvc(); }
3、修改项目属性,生成xml文档
4.设置默认启动