【问题标题】:Problem with publishg net core API into Azure将网络核心 API 发布到 Azure 的问题
【发布时间】:2021-07-20 07:53:21
【问题描述】:

我有一个 net core 3.1 REST API,我想将它发布到 Azure。我开始关注这篇文章: https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-azure-api-management-using-vs?view=aspnetcore-5.0

当我添加 Swagger 时,我在安装 Swashbuckle.AspNetCore 包的第 3 版后遇到了一般错误“HTTP ERROR 550.30”的问题。当我安装最后一个版本时,API 再次在本地工作,但我无法将其发布到 Azure,因为 swagger 无法制作 swagger JSON 文件。 我尝试了许多来自 GitHub 的建议,但没有任何效果! 注意:如果我从库移到 3.0.0 版,我可以发布 API,但会再次以“HTTP ERROR 550.30”结束

最后,我今天遇到了一个不同的错误,即使我没有更改代码上的任何内容: 'Web 部署任务失败。 (Web Deploy 无法修改目标上的文件“BuildingRestAPI.dll”,因为它被外部进程锁定。为了使发布操作成功,您可能需要重新启动应用程序以释放锁定或使用 AppOffline .Net 应用程序在您下次尝试发布时的规则处理程序。在http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE 了解更多信息。'

我会接受任何帮助,因为我的任务时间不多了,而且我已经在这个问题上浪费了三天时间 提前谢谢你

【问题讨论】:

    标签: asp.net-core azure-web-app-service


    【解决方案1】:

    您确定收到HTTP ERROR 550.30 吗?因为我认为它应该是HTTP ERROR 500.30

    我关注了您发布的 article 并使用版本 3 和最新的 Swashbuckle.AspNetCore 包测试了代码。使用最新版本时,我的 api 应用程序在本地和 Azure 上都运行良好,我可以通过这些 api 看到 Swagger.json 文件:

    https://{your-website}/swagger/v1/swagger.json
    https://{your-website}/swagger/index.html
    

    使用 3.0.0 版本时,由于不兼容的问题,我的项目无法发布。看来我的项目使用了高.net core版本,Swashbuckle.AspNetCore包版本太低,无法支持。

    这是我的Startup.cs

    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    using Microsoft.Extensions.Logging;
    using NLog.Extensions.Logging;
    
    namespace TodoApi
    {
        public class Startup
        {
            private readonly string swaggerBasePath = "api/app";
            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.AddSwaggerGen();
                services.AddLogging(builder =>
                {
                    builder.SetMinimumLevel(LogLevel.Information);
                    builder.AddNLog("nlog.config");
                });
            }
    
            // 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.UseHttpsRedirection();
    
                app.UseSwagger();
    
                app.UseRouting();
    
                app.UseAuthorization();
    
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllers();
                });
            }
        }
    }
    
    1. 更新Swashbuckle.AspNetCore包版本到更高版本,比如5.0.0,避免最新版本出现一些未知问题,看看本地能不能用。
    2. 当它在本地运行良好时,您可以再次发布,如果仍然出现错误,请使用 kudu 上的日志进行诊断。

    【讨论】:

      猜你喜欢
      • 2020-05-14
      • 2017-08-06
      • 2019-09-25
      • 2021-04-02
      • 1970-01-01
      • 2020-09-07
      • 1970-01-01
      • 2018-03-24
      • 1970-01-01
      相关资源
      最近更新 更多