Search code examples
c#asp.netasp.net-coreswagger-ui

How to include XML comments files in Swagger in ASP.NET Core


I need Swagger generate API documentation include UI to test operations.

When use ASP.NET in my project, deps XML files are generated, everything is OK, look like this:

enter image description here

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:

enter image description here

And when I deploy my project to IIS, the project XML not in deploy files list.


Solution

  • 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.

    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>
    

    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.