1、 在NuGet中搜索 Swashbuckle
2、 安装Swashbuckle
3、 Swashbuckle 是通过生成的XML文件来读取注释的,生成 SwaggerUI,JSON 配置中的说明的,安装时会在项目目录 App_Start 文件夹下生成一个 SwaggerConfig.cs 配置文件,用于配置 SwaggerUI 相关展示行为的。如图:
将配置文件第99行,注释去掉,并修改为:
c.IncludeXmlComments(string.Format(@"{0}\bin\{1}.XML", AppDomain.CurrentDomain.BaseDirectory,thisAssembly.GetName().Name));
4、 紧接着你在此Web项目属性选型,生成选卡中选择“XML 文档文件”
5、 随便创建个webApi文件添加注释
using System;
usingSystem.Collections.Generic;
using System.Linq;
using System.Net;
usingSystem.Net.Http;
usingSystem.Web.Http;
usingClassLibrary1;
namespace WebApplication1.Controllers
{
[Authorize]
publicclass ValuesController :ApiController
{
//some code.....
/// <summary>
/// 根据ID获取一个值
/// </summary>
/// <param name="id">值的ID</param>
/// <remarks>当前方法根据ID获取一个值</remarks>
/// <returns>返回</returns>
public string Get(int id)
{
return "value";
}
// some code ....
}
}
6、 好了接下来F5 运行程序,
地址:http://localhost:50445/swagger/ui/index
就可以看到你所有wabapi的接口以及注释了!还可以调试接口
转载于:https://blog.51cto.com/brucezhang51/1749216