【问题标题】:Problem with swagger file in release mode发布模式下swagger文件的问题
【发布时间】:2019-12-26 20:50:20
【问题描述】:

我正在构建一个在 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.net azure docker asp.net-core swagger


【解决方案1】:

这个问题是已知的,并且已经深入讨论here

正如this 评论中提到的,包括以下内容对我有用:

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

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

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

【讨论】:

    【解决方案2】:

    这些答案为我指明了正确的方向。我从属性组中删除了条件,以便无论构建类型(调试/发布)如何,它都可以正常工作。

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

    会变成:

    <PropertyGroup>
        <DocumentationFile>C:\Users\xyz\source\repos\sms-test\Web\Web.xml</DocumentationFile>
    </PropertyGroup>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-13
      • 2011-02-25
      • 1970-01-01
      • 1970-01-01
      • 2020-09-20
      相关资源
      最近更新 更多