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

查看:133
本文介绍了Azure App服务无法启动,因为它无法使用ASP.NET Core查找庞大的文档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:\home\site\wwwroot\APIProject.xml'。

FileNotFoundException: Could not find file 'D:\home\site\wwwroot\APIProject.xml'.

文件已放置在bin\Debug\netcoreapp2.0
中可在本地使用,但发布到Azure App服务时会崩溃。

The file is placed in bin\Debug\netcoreapp2.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();

我正在尝试使用Debug模式发布。还尝试使用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查找庞大的文档xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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