Azure App Service API gets FileNotFoundException: Could not find file 'D:\home\site\wwwroot\MyApi.xml when trying to start swagger

谁都会走 提交于 2019-12-11 08:03:24

问题


I am working on an ASP.NET Core 2.2 API deployed to Azure App Services. I am deploying to a DEV slot.

I am using Swagger, which works fine on my localhost, but when I go to the URL of by DEV slot and use /swagger, I get the error;

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

I have the following in my *.csproj file;

<PropertyGroup>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>  

And when I go to Kudu for the DEV slot, I can see the MyApi.xml file in the /site/wwwroot folder. If I edit it in Kudu, I can see that the content is as expected.

In my project's Startup.cs class --> Configure method, I have;

app.UseStaticFiles(); 

This is similar to the SO post here but in that post, the file was not actually showing up in wwwroot, whereas in my case, it does.

The API otherwise works correctly in that I can use Postman to test all of the APIs endpoints in the DEV slot. It is just that when I try to access DEV slot URL + /swagger from Chrome, I get the FileNotFound exception.

My Startup.cs --> ConfigureServices method has the following;

services.AddSwaggerGen(
    options =>
    {
        // integrate xml comments
        options.IncludeXmlComments(XmlCommentsFilePath);
    });

and the XmlCommentsFilePath method is below;

private static string XmlCommentsFilePath
{
    get
    {
        var basePath = PlatformServices.Default.Application.ApplicationBasePath;
        var fileName = typeof(Startup).GetTypeInfo().Assembly.GetName().Name + ".xml";
        return Path.Combine(basePath, fileName);
    }
}

I assume that the Swagger setup is correct since it works locally and the error I get when deployed to the DEV slot is the FileNotFound pointing to D:\home\site\wwwroot\MyApi.xml where that file actually does exist according to Kudu for that slot.

UPDATE 1

I also tried the recommendation for ASP.NET 2.2 in this SO link with no luck.

What am I missing here?


回答1:


Please make sure you have something like following PropertyGroup in csproj in release mode

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DocumentationFile>bin\Release\netcoreapp2.2\APIProject.xml</DocumentationFile>
</PropertyGroup>

Also please make sure you are referring to the same .xml file in c# project. See if it helps.

And remember that under Project Properties, in the "Build" tab, you need to tick the "XML documentation file" box.

P.S. Please use the respected Dot Net Core Version which you are using in your project.



来源:https://stackoverflow.com/questions/55300452/azure-app-service-api-gets-filenotfoundexception-could-not-find-file-d-home-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!