Swagger生成WebAPI文档

最近在做WebAPI2.0 项目,为了使用者能轻易查看API文档,因此使用Swagger进行了配置

 

1.打开程序包管理控制台输入:

Install-Package Swashbuckle

 

2.在对应项目里的App_Start文件夹下的SwaggerConfig.cs文件找到:

c.IncludeXmlComments 

然后进行替换

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

 

3.然后再与Register方法平级的地方增加一个方法

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

 

4.右键项目->属性->生成->勾选(XML文档文件)->保存

 

5.最后就是访问地址了

http://localhost:82/swagger/ui

 

 

posted @ 2017-02-21 12:28  任意球  阅读(1104)  评论(0编辑  收藏  举报