【发布时间】:2017-04-18 16:22:38
【问题描述】:
尝试为我的新启动 ASP.NET Core api 项目配置 swagger 时出错。它在本地主机上完美运行:评论与 xml 评论配合得很好。但是当我将它发布到 azure 主机时,它不起作用。
然后我试图找出方法是注释将xml注释添加到swagger的配置代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddMvcCore().AddApiExplorer();
services.AddLogging();
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
});
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
{
Version = "v1",
Title = " API Helper Page",
Description = "A simple start ASP.NET Core Web API/ MBAAS",
TermsOfService = "None",
Contact = new Contact { Name = "Nguyễn Bá Nguyên", Email = "", Url = "https://github.com/hello/" },
License = new License { Name = "Under Construction...", Url = " " }
});
// Set the comments path for the swagger json and ui.
// only working on local, need to be fixed
var basePath = PlatformServices.Default.Application.ApplicationBasePath;
var xmlPath = Path.Combine(basePath, ".xml");
c.IncludeXmlComments(xmlPath);
});
}
为了在没有错误的情况下发布到天蓝色,我评论了最后一个
//var basePath = PlatformServices.Default.Application.ApplicationBasePath;
//var xmlPath = Path.Combine(basePath, ".xml");
//c.IncludeXmlComments(xmlPath
);
和天蓝色的主机工作,但招摇不能使用xml评论:(
那么有什么方法可以配置 swagger 以对 azure 主机使用 xml 注释?
【问题讨论】:
-
尝试在你的项目中显式包含生成的 xml 文件,然后它应该包含在发布到 azure 步骤中,并且无需通过 kudu/FTP 手动上传即可使用。
-
@rory_za 你知道如何PlatformServices.Default.Application.ApplicationBasePath 找到xml注释文件(当我们配置时自动生成:解决方案资源管理器->属性->构建->输出->单击复选框XML 文档文件并选择输出路径)。那么我应该在哪里包含自动生成的生成的 xml 文件?
-
将其设置为构建文件,然后至少构建一次项目,然后将生成的文件作为“现有项目”添加到您的项目中。
标签: c# azure asp.net-core swagger