【发布时间】:2021-08-10 17:21:53
【问题描述】:
得到错误:
发布遇到错误。 确保您的应用程序的 Startup.cs 从 ConfigureServices 中调用 AddSwaggerGen 以生成 swagger 文件。
但是startup.cs这里已经满载:
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "WeatherForecast API", Version = "v1" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("v1/swagger.json", "WeatherForecast API V1");
});
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
【问题讨论】:
-
尝试清理并重建应用程序,然后重新发布应用程序。另外,在我的asp.net 5应用程序中,我使用默认的SwaggerEndPoint如下:
app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "APIApp v1"));,然后将应用程序发布到IIS,一切正常,所以你可以尝试使用这个SwaggerEndpoint。
标签: .net asp.net-core swagger publish