My project builds successfully, but on publishing to Azure this error occurs:
Microsoft.WebTools.Shared.Exceptions.WebToolsException: Be sure that the Startup.cs for your application is calling AddSwaggerGen from within ConfigureServices in order to generate swagger file. Visit /?LinkId=2131205&CLCID=0x409 for more information.
at Microsoft.WebTools.Azure.Publish.ApiMApi.BaseApiMApiUpdater.EmitTerminatingError(String bucketName, String displayedErrorMessage, String loggedErrorMessage) at Microsoft.WebTools.Azure.Publish.ApiMApi.AppServiceApiMApiPublishHandler.AppServiceApiMApiUpdater.<GenerateSwaggerToBuildOutputDirAsync>d__12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.WebTools.Azure.Publish.ApiMApi.AppServiceApiMApiPublishHandler.AppServiceApiMApiUpdater.<RunUpdateAsync>d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.WebTools.Azure.Publish.ApiMApi.BaseApiMApiUpdater.<RunUpdateWithTelemetryAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.WebTools.Azure.Publish.ApiMApi.AppServiceApiMApiPublishHandler.<UpdateApiMApiAsync>d__14.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.WebTools.Azure.Publish.NewFx.Profiles.BaseSwaggerPublishStep.<RunAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Publish.Framework.Profiles.ProjectProfilesManager.<RunPublishStepsAsync>d__44.MoveNext()
I am using .NET 8 and Visual Studio 2024 and I am registering the Swagger UI in my application.
here is my program.cs file
using Application.Abstractions;
using Infrastructure;
using Infrastructure.Context;
using Infrastructure.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using WebAPI.Middleware;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddDbContext<BreaKonfusionContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("BreaKonfusionContext"))
);
builder.Services.AddApplication();
builder.Services.AddApplicationCQRS();
builder.Services.AddProblemDetails();
builder.Services.AddInfrastructure(builder.Configuration);
builder.Services.AddControllers();
builder.Services.AddTodoControllers();
builder.Services.AddSignalR();
// Learn more about configuring Swagger/OpenAPI at
builder.Logging.AddAzureWebAppDiagnostics();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(option =>
{
option.SwaggerDoc("v1", new OpenApiInfo { Title = "BreaKonfusion API", Version = "v1" });
option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Description = "Please enter a valid token",
Name = "Authorization",
Type = SecuritySchemeType.Http,
BearerFormat = "JWT",
Scheme = "Bearer"
});
option.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type=ReferenceType.SecurityScheme,
Id="Bearer"
}
},
new string[]{}
}
});
});
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Logging.AddDebug();
builder.Services.AddScoped<ExceptionHandlingMiddleware>();
var app = builder.Build();
app.UseRouting();
// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Breakonfusion API V1");
});
app.UseCors(CorsExtensions.MyAllowSpecificOrigins);
// await app.Services.InitializeDbAsync();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.UseMiddleware<ExceptionHandlingMiddleware>();
app.UseCurrentUser();
app.MapTodoHubs();
app.MapControllers();
app.Run();
My project builds successfully, but on publishing to Azure this error occurs:
Microsoft.WebTools.Shared.Exceptions.WebToolsException: Be sure that the Startup.cs for your application is calling AddSwaggerGen from within ConfigureServices in order to generate swagger file. Visit https://go.microsoft/fwlink/?LinkId=2131205&CLCID=0x409 for more information.
at Microsoft.WebTools.Azure.Publish.ApiMApi.BaseApiMApiUpdater.EmitTerminatingError(String bucketName, String displayedErrorMessage, String loggedErrorMessage) at Microsoft.WebTools.Azure.Publish.ApiMApi.AppServiceApiMApiPublishHandler.AppServiceApiMApiUpdater.<GenerateSwaggerToBuildOutputDirAsync>d__12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.WebTools.Azure.Publish.ApiMApi.AppServiceApiMApiPublishHandler.AppServiceApiMApiUpdater.<RunUpdateAsync>d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.WebTools.Azure.Publish.ApiMApi.BaseApiMApiUpdater.<RunUpdateWithTelemetryAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.WebTools.Azure.Publish.ApiMApi.AppServiceApiMApiPublishHandler.<UpdateApiMApiAsync>d__14.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.WebTools.Azure.Publish.NewFx.Profiles.BaseSwaggerPublishStep.<RunAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Publish.Framework.Profiles.ProjectProfilesManager.<RunPublishStepsAsync>d__44.MoveNext()
I am using .NET 8 and Visual Studio 2024 and I am registering the Swagger UI in my application.
here is my program.cs file
using Application.Abstractions;
using Infrastructure;
using Infrastructure.Context;
using Infrastructure.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using WebAPI.Middleware;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddDbContext<BreaKonfusionContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("BreaKonfusionContext"))
);
builder.Services.AddApplication();
builder.Services.AddApplicationCQRS();
builder.Services.AddProblemDetails();
builder.Services.AddInfrastructure(builder.Configuration);
builder.Services.AddControllers();
builder.Services.AddTodoControllers();
builder.Services.AddSignalR();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Logging.AddAzureWebAppDiagnostics();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(option =>
{
option.SwaggerDoc("v1", new OpenApiInfo { Title = "BreaKonfusion API", Version = "v1" });
option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Description = "Please enter a valid token",
Name = "Authorization",
Type = SecuritySchemeType.Http,
BearerFormat = "JWT",
Scheme = "Bearer"
});
option.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type=ReferenceType.SecurityScheme,
Id="Bearer"
}
},
new string[]{}
}
});
});
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Logging.AddDebug();
builder.Services.AddScoped<ExceptionHandlingMiddleware>();
var app = builder.Build();
app.UseRouting();
// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Breakonfusion API V1");
});
app.UseCors(CorsExtensions.MyAllowSpecificOrigins);
// await app.Services.InitializeDbAsync();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.UseMiddleware<ExceptionHandlingMiddleware>();
app.UseCurrentUser();
app.MapTodoHubs();
app.MapControllers();
app.Run();
Share
Improve this question
edited Nov 21, 2024 at 10:17
Dai
156k30 gold badges305 silver badges424 bronze badges
asked Nov 16, 2024 at 14:56
Awwal15Awwal15
113 bronze badges
8
|
Show 3 more comments
1 Answer
Reset to default 0Please try to upgrade your vscode to latest version. And install Azure Resources
, Azure App Service
extensions.
If you have sign in the azure account, please sign out and sign in again.
If the issue still occurs, we can deploy the project via azure cli. If we can deploy it successfully via command, then we can confirm there is no-permission issue with your account.
Here is the detailed steps.
PS C:\Users\Jason\source\repos\ReactApp4\WebApplication1> dotnet publish -c Release -o ./publish
PS C:\Users\Jason\source\repos\ReactApp4\WebApplication1> Compress-Archive -Path "C:\Users\Jason\source\repos\ReactApp4\WebApplication1\publish\*" -DestinationPath "C:\Users\Jason\source\repos\ReactApp4\WebApplication1\publish.zip"
PS C:\Users\Jason\source\repos\ReactApp4\WebApplication1> az webapp deploy --resource-group jasonp2 --name jasontestwebapp --src-path "C:\Users\Jason\source\repos\ReactApp4\WebApplication1\publish.zip" --type zip
If we can deployed successfully, then we can also deploy this way, not sure if it's caused by extensions.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745655905a4638539.html
app.UseSwagger(); app.UseSwaggerUI(x => { x.SwaggerEndpoint("/swagger/v1/swagger.json", "Web API V1"); if(app.Environment.IsDevelopment()) x.RoutePrefix = "swagger"; // For localhost else x.RoutePrefix = string.Empty; // For azure } );
in your program.cs file. – Aslesha Kantamsetti Commented Nov 16, 2024 at 17:13