5

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Also see github.com/dotnet/sdk/issues/795 asking for this support in the core tooling. It also has a few workarounds listed.
Is this the preferred way in .NET Core 3.1 too?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.