asp.net - 发布模式下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。
解决方案
这个问题是已知的,并已在此处进行了深入讨论。
如本评论中所述,包括以下内容对我有用:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>C:\Users\xyz\source\repos\sms-test\Web\Web.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
我还看到代码片段与您在上面发布的错误消息之间的路径不匹配。您可能也想检查一下。
推荐阅读
- shell - kubectl replace -f 说它已经替换了一个资源,但实际上没有
- sql-server - SQL 基础数据类型
- php - PHP从某个点写入文件
- r - 我想计算时间之间的时间差
- django - Django Rest Framework - 如何在 POST 时设置 current_user
- javascript - Javascript 按钮禁用然后立即启用
- google-chrome - Chrome 扩展:如何检查使用 pac 脚本设置的代理是否有效
- database - 为什么我会收到“找不到数据源名称且未指定默认驱动程序”,我该如何解决?
- tensorboard - TensorBoard 不会实时更新
- javascript - 如何使用javascript删除firestore上的所有文档