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: https://github.com/dotnet/sdk/issues/795

I modified it a bit and the result is:

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

<ItemGroup>

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

</ItemGroup>

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

</Target>

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

Comments

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" />

developers.de is a .Net Community Blog powered by daenet GmbH.