Azure App 服务无法启动,因为它使用 ASP.NET Core 找不到 swagger 文档 xml [英] Azure App service can't start because it can't find swagger documentation xml using ASP.NET Core

查看:32
本文介绍了Azure App 服务无法启动,因为它使用 ASP.NET Core 找不到 swagger 文档 xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新 2: 文件未发布.那是错的.但是,我无法弄清楚为什么我的一台计算机可以以正确的方式发布它而另一台在 Visual Studio 升级后不能.

Update 2: The file does not get published. That is what is wrong. However, I can't figure out why one of my computers can publish it the right way and the other doesn't after the Visual studio upgrade.

更新:在两台不同的计算机上运行相同的解决方案,其中 APIProject.xml 文件从一台计算机正确发布但另一台计算机未正确发布,现在只剩下一个差异.发布工作的计算机运行未更新版本的 Visual Studio 2017 Enterprise.15.5.2 不起作用,而 15.4.2 起作用.

Update: Running the same solution on two different computers where the APIProject.xml file get's correctly published from one computer but not the other there are now only one difference left. The computer from which the publishing works runs the not updated version of Visual studio 2017 Enterprise. 15.5.2 does not work and 15.4.2 works.

我收到此错误:

FileNotFoundException: 找不到文件'D:homesitewwwrootAPIProject.xml'.

FileNotFoundException: Could not find file 'D:homesitewwwrootAPIProject.xml'.

文件放在binDebug etcoreapp2.0它在本地工作,但在发布到 Azure App 服务时会崩溃.

The file is placed in binDebug etcoreapp2.0 It works locally but when published to Azure App service it crashes.

我正在发布到我创建的暂存槽,但尚未尝试生产.发布将替换目的地的所有文件.

I'm publishing to the staging slot I created and haven't tried production yet. Publishing replaces all files at destination.

这是我的 Swagger 设置,但它曾经可以工作 :)

Here is my setup of Swagger but it used to work :)

public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        // Register the Swagger generator, defining one or more Swagger documents
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info
            {
                Version = "v1",
                Title = "Ecommerce/Product API",
                Description = "Handles API based shopping functionality",
                TermsOfService = "Terms of service should be contracted with inidividually",
                Contact = new Contact { Name = "Magnus", Email = "magnus@secret", Url = "" },
                License = new License { Name = "Use under permission from our Group", Url = "http://aboutno" }
            });

            // Set the comments path for the Swagger JSON and UI.
            var basePath = PlatformServices.Default.Application.ApplicationBasePath;
            var xmlPath = Path.Combine(basePath, "APIProject.xml");
            c.IncludeXmlComments(xmlPath);
        });   
    }

改变的是我在 Program.cs 中添加了UseSetting"行来获取它为什么不启动的错误.在添加该行之前,我没有收到开发人员错误,只有最终用户错误页面.

What has changed is I added the "UseSetting"-row in Program.cs to get errors of why it doesn't start. Before adding that row I did't get developer error, only got end user error page.

public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseApplicationInsights()
            .UseSetting(WebHostDefaults.DetailedErrorsKey, "true")
            .UseStartup<Startup>()
            .Build();

我正在尝试使用调试模式发布.也尝试使用 Release 作为下面的一个答案,但没有区别.

I'm trying to publish with Debug mode. Also tried with Release as of one answer below but no difference.

我检查了另一台计算机上的代码并从那台计算机上发布,所以问题对我来说变得更奇怪了!

I checked out the code in another computer and publishing from that computer works so the problem just got more weird to me!

推荐答案

我的 .Net Core 2.0 应用程序在本地运行良好,但抛出一个毫无意义的启动应用程序时发生错误."部署到 Azure 时出错.

My .Net Core 2.0 app worked fine locally, but threw a pointless "An error occurred while starting the application." error when deployed to Azure.

检查日志,原因是 Swagger 找不到特定的 .xml 文件(为什么错误消息没有让我们知道?!)

Checking the logs, the cause was that Swagger couldn't find a particular .xml file (why the hell doesn't the error message let us know ?!)

解决方案是选择构建"选项卡,将配置"下拉列表更改为发布",然后勾选此框:

The solution was to select the Build tab, change the Configuration drop down list to "Release", then tick this box:

就是这样.

由于某种原因,默认情况下它被勾选(填充了 .xml 文件名)用于调试,而不是用于发布.

For some reason, by default it was ticked (with the .xml filename filled in) for Debug, but not for Release.

(叹气.)

这篇关于Azure App 服务无法启动,因为它使用 ASP.NET Core 找不到 swagger 文档 xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆