C#Swagger使用

1.新建的web项目带有webapi

2.Nuget包新增Swagger

或者也可以输入代码

Install-Package Swashbuckle

3.修改SwaggerConfig,大概108行

c.IncludeXmlComments(GetXmlCommentsPath(thisAssembly.GetName().Name));

增加方法

protected static string GetXmlCommentsPath(string name)
{
    return System.String.Format(@"{0}\bin\{1}.xml",System.AppDomain.CurrentDomain.BaseDirectory, name);
}

4.然后自己新建控制器,继承APIController

5.然后运行访问http://<youhost>/swagger/ui/index,最终显示效果