Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I publish XML documentation with a .net core web application?

Tags:

c#

.net-core

In the csproj file I've enabled XML documentation generation via the following tag:

  <PropertyGroup>
    <DocumentationFile>bin\xml\Project.Api.xml</DocumentationFile>
    <NoWarn>1701;1702;1705;1591;1573</NoWarn>
  </PropertyGroup>

This works and correctly builds xml docs. Now I need this XML file to be distributed with the application (for Swagger support among other things). So I added the following:

  <ItemGroup>
    <None Update="bin\xml\Project.Api.xml">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>      
    </None>
  </ItemGroup>

However, when I publish to a folder (or to azure) the XML doc is no where to be found.

What am I missing?

like image 460
KallDrexx Avatar asked Oct 18 '22 15:10

KallDrexx


1 Answers

The following works for me in your scenario (at least when publishing to folder):

  <!-- Run before PrepareForPublish target -->
  <Target Name="CopyDocumentationFile" BeforeTargets="PrepareForPublish">
    <ItemGroup>      
      <DocFile Include="$(DocumentationFile)" />
    </ItemGroup>
    <!--just copy doc file to target location -->
    <Copy SourceFiles="@(DocFile)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true" />
  </Target>

Here you can find docs about how to include custom files into publish output in general. They use more complicated way, but just a little bit more.

like image 144
Evk Avatar answered Oct 20 '22 10:10

Evk