在类库或者api项目上右键--属性--生成--输出--XML文档文件上打√,
然后在Startup.cs中ConfigureServices添加如下配置即可:
services.AddSwaggerGen(config => { //var provider = services.BuildServiceProvider().GetRequiredService<IApiVersionDescriptionProvider>(); config.SwaggerDoc("v1", new OpenApiInfo { Title = "CL.MEStoWMS.WebApi", Version = "v1" }); // 为 Swagger JSON and UI设置xml文档注释路径 var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径) var xmlPath = Path.Combine(basePath, "MEStoWMS.WebApi.xml");//接口action显示注释 var xmlPath_entity = Path.Combine(basePath, "实体类库.xml");//分层实体显示注释 config.IncludeXmlComments(xmlPath); config.IncludeXmlComments(xmlPath_entity); });