.netcore 3.1中使用swagger顯示注釋
解決方案
一、勾選xml文檔文件
項目--> 右鍵屬性--> 生成-->勾選xml文檔文件,系統會默認生成一個文件,並拷貝最后的名稱.xml
二、 Startup.cs文件配置參數
添加代碼截圖
添加代碼如下
var basePath = AppContext.BaseDirectory;
//配置swagger注釋
var xmlPath = Path.Combine(basePath, "WebCoreAPI.xml");
//把接口文檔的路徑配置進去。第二個參數表示是否開啟包含對Controller的注釋容納
c.IncludeXmlComments(xmlPath, true); //默認的第二個參數是false,修為true
或者
var xmlPath = Path.Combine(Microsoft.DotNet.PlatformAbstractions.ApplicationEnvironment.ApplicationBasePath,
"WebCoreAPI.xml");// 配置接口文檔文件路徑
c.IncludeXmlComments(xmlPath, true);
三、注釋正常顯示