首页 > 解决方案 > 发布模式下swagger文件的问题

问题描述

我正在构建在 docker linux 容器中运行的 asp.net 核心中的应用程序。我的应用程序在调试模式下运行良好,但是当我尝试在发布模式和邮递员下运行它时,我收到错误消息“FileNotFoundException:找不到文件'/app/AuthorAdmin.Command.API.XML'”。

请找到我的 startup.cs 文件,如下所示:

services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new Info
    {
        Version = "v1",
        Title = "Taxathand AuthorAdminAPI",
        Description = "Taxathand AuthorAdminAPI",
        TermsOfService = "None",
        Contact = new Contact() { Name = "tax@hand Author", Email = "prteja@deloitte.com", Url = "" }
    });

    //Locate the XML file being generated by ASP.NET...
    var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.XML";
    var xmlPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, xmlFile);

    //... and tell Swagger to use those XML comments.
    c.IncludeXmlComments(xmlPath);
});

我的项目文件代码如下:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DocumentationFile>CommandStack\AuthorAdmin.Command.API\AuthorAdmin.Command.API.xml</DocumentationFile>
    <NoWarn>1701;1702;1591</NoWarn>
    <OutputPath>bin\Debug\netcoreapp2.2\</OutputPath>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <OutputPath>bin\Release\netcoreapp2.2\</OutputPath>
    <DocumentationFile>bin\Release\netcoreapp2.2\AuthorAdmin.Command.API.xml</DocumentationFile>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <NoWarn>1701;1702;1591</NoWarn>
  </PropertyGroup>

我想以类似于调试模式的发布模式访问 api。

标签: asp.netazuredockerasp.net-coreswagger

解决方案


这个问题是已知的,并已在此处进行了深入讨论。

评论中所述,包括以下内容对我有用:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DocumentationFile>C:\Users\xyz\source\repos\sms-test\Web\Web.xml</DocumentationFile>
  </PropertyGroup>

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

我还看到代码片段与您在上面发布的错误消息之间的路径不匹配。您可能也想检查一下。


推荐阅读