//獲取應用程序所在目錄的2種方式(絕對,不受工作目錄影響,建議采用此方法獲取路徑).如:d:\Users\xk\Desktop\WebApplication1\WebApplication1\bin\Debug\netcoreapp2.0\ String basePath1 = AppContext.BaseDirectory; String basePath2 =Path.GetDirectoryName(typeof(Program).Assembly.Location); //注意:對於 Linux 或非 Windows 操作系統,文件名和路徑區分大小寫。 例如,“SwaggerDemo.xml”文件在 Windows 上有效,但在 CentOS 上無效。 String path =Path.Combine(basePath2, "SwaggerDemo.xml");