1.工具->Guget包管理器->程序包管理器控制台
2.控制台中输入 Install-Package Swashbuckle.AspNetCore -Version 5.5.0
3.在startup中配置启动项
public void ConfigureServices(IServiceCollection services)' { services.AddSwaggerGen(m => { m.SwaggerDoc("V1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "swaggerTest", Version = "V1" }); }); services.AddControllers(); }
`
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseSwagger();
app.UseSwaggerUI( m => {
m.SwaggerEndpoint("/swagger/V1/swagger.json","swaggerTest");
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
`
4.launchsettings中配置默认启动页
profiles-> "launchUrl": "swagger/index.html",