【发布时间】:2022-02-11 15:41:42
【问题描述】:
我有一个简单的 ASP.NET Core 3.1 应用程序,我正在尝试将其发布到 Azure。
但发布失败并出现以下错误:
发布遇到错误。确保您的 Startup.cs 应用程序正在从 ConfigureServices 中调用 AddSwaggerGen 为了生成招摇文件。访问 https://go.microsoft.com/fwlink/?LinkId=2131205&CLCID=0x409 了解更多 信息。
但它配置正确并且在本地启动时运行良好。因此,我不确定出了什么问题或如何传递此错误。
Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddDbContext<TestProductContext>(options =>
{
options.UseSqlServer(Configuration["ConnectionStrings:Database"]);
});
services.AddControllers().AddOData(opt =>
opt.Filter().Expand().Select().OrderBy().Count().SetMaxTop(100)
.AddRouteComponents("odata", GetEdmModel()));
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "OdataTestProject", Version = "v1" });
c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
});
//// https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters#filter-scopes-and-order-of-execution
services.AddMvc(opts => { opts.Filters.Add(new AutoLogAttribute()); });
services.AddApplicationInsightsTelemetry();
}
// 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(c =>
{
c.RouteTemplate = "/swagger/{documentName}/swagger.json";
});
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "OdataTestProject v1"));
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
private static IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
var entitySet = builder.EntitySet<TestProduct>("TestProducts");
entitySet.EntityType.HasKey(entity => entity.Id);
return builder.GetEdmModel();
}
}
【问题讨论】:
标签: c# azure asp.net-core asp.net-web-api azure-web-app-service