先在ProjectName.csproj文件里节点PropertyGroup内添加代码:
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
然后在StartUp.cs文件内方法ConfigureServices的services.AddSwaggerGen内添加代码:
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; //引用System.Reflection
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); //引用System.IO;
c.IncludeXmlComments(xmlPath);
最后项目启动即可