Search code examples
asp.netpublishvisual-studio-2019swashbuckle

Referenced assemblies' xml docs not copied during publish


When publishing an ASP.NET project (NET Framework 4.7.1) referencing class libraries (projects) in same solution, all of which have XML documentation generated as part of their build, only the ASP.NET project's own XML documentation file is included in published output.

These files are necessary for API docs with Swashbuckle.

This is only an issue during publish from VS, not regular builds. I'm using VS Professional 2019 v16.4.2.

How do I include the referenced class libraries' XML documentation files as part of the publish? It seems like such a normal use case that I feel like I'm missing something obvious.

I've tried:

  • Including XML files in said projects and marking them as "Content" and "Copy always" to output dir. No change.
  • Changing different publish settings, none of which seem to have any effect on this

Solution

  • Loosely based on Sam Stephens blog post I've added this to the project file, which copies all xml files to bin folder during publish. If someone comes up with a simpler approach, don't hesitate to post an answer :)

    <PropertyGroup>
      <CopyAllFilesToSingleFolderForPackageDependsOn>
        $(CopyAllFilesToSingleFolderForPackageDependsOn);
        CopyXmlDocuments;
      </CopyAllFilesToSingleFolderForPackageDependsOn>
    </PropertyGroup>
    <Target Name="CopyXmlDocuments">
      <ItemGroup>
        <XmlDocuments Include="$(OutDir)*.xml" />
        <FilesForPackagingFromProject Include="%(XmlDocuments.Identity)">
          <DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
        </FilesForPackagingFromProject>
      </ItemGroup>
    </Target>