dee*_*zen 8 swagger asp.net-core-mvc swashbuckle asp.net-core asp.net-core-1.0
我已经将Swashbuckle包添加到我的ASP核心项目中.
我想将Swagger配置为使用VS xml注释自动生成.
问题是我找不到获取该位置的方法:
PlatformServices.Default.Application.ApplicationBasePath - 指向项目根路径Directory.GetCurrentDirectory() - 相同Path.GetFullPath(".") - 相同IHostingEnvironment.WebRootPath - 相同输出文件夹<project>.xproj由BaseIntermediateOutputPath选项配置.
但我无法在运行时获取此位置.
var pathToDoc = "????";
options.OperationFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlActionComments(pathToDoc));
Run Code Online (Sandbox Code Playgroud)
我看到的解决方案不好
但我想将它与Docker,CI,localhost一起使用,所以我认为这不是使用硬编码解决方案的最佳解决方案.
小智 2
您可以尝试以下函数来获取 XML 文件路径
private string GetXmlCommentsPath()
{
var app = PlatformServices.Default.Application;
return System.IO.Path.Combine(app.ApplicationBasePath, System.IO.Path.ChangeExtension(app.ApplicationName, "xml"));
}
Run Code Online (Sandbox Code Playgroud)
xml 文件与应用程序同名。我目前在我的项目中使用此代码并且运行良好。
| 归档时间: |
|
| 查看次数: |
1227 次 |
| 最近记录: |