如何在ASP.NET Core的Swagger中包含XML注释文件 [英] How to include XML comments files in Swagger in ASP.NET Core
问题描述
我需要Swagger生成包含UI的API文档来测试操作.
I need Swagger generate API documentation include UI to test operations.
在我的项目中使用ASP.NET时,将生成deps XML文件,一切正常,如下所示:
When use ASP.NET in my project, deps XML files are generated, everything is OK, look like this:
但是当我在项目中使用ASP.NET Core时,不会生成deps XML文件.它只是生成我的项目注释XML文件,如下所示:
But when I use ASP.NET Core in my project, deps XML files are not generated. It just generates my project comments XML file, look like this:
当我将项目部署到IIS时,项目XML不在部署文件列表中.
And when I deploy my project to IIS, the project XML not in deploy files list.
推荐答案
为您依赖的每个项目启用"XML文档文件"复选框 ,以便在构建时生成其文件.可以在项目的属性构建"选项卡上完成.
Enable "XML documentation file" checkbox for each project you depend on to generate their files on build. It could be done at project's properties Build tab.
要包括所有部署中的XML文件,请将此目标添加到已发布项目的 csproj
文件中:
To include all XML files on deploy, add this target to the published project's csproj
file:
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
<ItemGroup>
<DocFile Include="bin\*\*\*.xml" />
</ItemGroup>
<Copy SourceFiles="@(DocFile)"
DestinationFolder="$(PublishDir)"
SkipUnchangedFiles="false" />
</Target>
这会将所有XML文件从 bin
文件夹和嵌套的子文件夹(例如 bin \ Release \ netcoreapp1.1 \
)复制到 publish
目录.当然,您可以自定义该目标.
This will copy all XML files from bin
folder and nested subfolders (like bin\Release\netcoreapp1.1\
) to publish
dir. Of course you can customize that target.
这篇关于如何在ASP.NET Core的Swagger中包含XML注释文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!