//注册Swagger生成器,定义一个和多个Swagger 文档 services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v1", Title = "eric's API", Description = "A simple example ASP.NET Core Web API", TermsOfService = "None", Contact = new Contact { Name = "eric", Email = string.Empty, Url = "http://www.eric.com/" }, License = new License { Name = "许可证名字", Url = "http://www.eric.com" } }); // 为 Swagger JSON and UI设置xml文档注释路径 //获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径) var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location); var xmlPath = Path.Combine(basePath, "SwaggerDemo.xml"); c.IncludeXmlComments(xmlPath); });