Include XML documentation in ASP.NET Core publish

I am using the auto generated XML file in Swagger. On my dev machine everything worked fine, but after publish the file was gone. This can result in an application crash on startup if you are not checking if the file exists before handing the filepath over to swagger.

At the moment there is no UI for adding the XML to the publish output. I searched the internet a bit and found this on github:

I modified it a bit and the result is:

<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">


<DocFile Include="bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\$(TargetName).xml" />


<Copy SourceFiles="@(DocFile)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="false" />


It uses placeholders to be generic and it can be used with any project.

Just add this to your *.csproj file and you are done.

Posted May 15 2017, 10:50 AM by Holger Vetter


Malcolm Learner wrote re: Include XML documentation in ASP.NET Core publish
on 09-20-2017 13:18

With a slight adjustment, you can target just the projects you need:

     <DocFile Include="bin\**\**\YOUR_PROJECT.xml" /> is a .Net Community Blog powered by daenet GmbH.