54

I consider it generally good practice to include the XML documentation file generated by the C# build in NuGet packages alongside the DLLs to provide intellisense documentation for consumers.

However, it's not clear to me how this can be done when building a package using VS 2017's project file format.

Is this possible?

Obviously I could switch over to maintaining a nuspec file but the VS2017 format is very convenient for keeping versions and dependencies all in one place.

ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
  • Possible duplicate: https://stackoverflow.com/questions/5205738/how-do-you-include-xml-docs-for-a-class-library-in-a-nuget-package/58165750#58165750 – bytedev Sep 30 '19 at 10:24

2 Answers2

74

As long as you set GenerateDocumentationFile in your csproj file like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>

</Project>

then all the defaults will generate the documentation file at the correct location and it will be included in the NuGet package.

If Visual Studio added DocumentationFile or other elements, you can delete them and replace it with the single GenerateDocumentationFile property.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • 8
    Worked like a charm! So frustrating that VS adds `DocumentationFile` instead – ChaseMedallion Feb 08 '18 at 01:50
  • But from what and where is this doc file going to be created? Where is that file/should be, where is the content? – Hrvoje Batrnek Jan 16 '19 at 21:08
  • 1
    You can still use the DocumentationFile element in the csproj to control where you want to output the XML file. Just remember in your .nuspec file to point to the same XML file in your file element. – bytedev Sep 30 '19 at 10:38
7

For other people who came in with the same problem - and if the accepted answer does not help...

Make sure that you have set the 'Include XML documentation' setting in the build configuration you are using (not just Debug, as by default)

In Visual Studio: enter image description here

or in csproj:

 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>
Bartosz
  • 4,406
  • 7
  • 41
  • 80
  • 3
    If you remove the Condition attribute it will generate the XML file for all build configurations. – bytedev Sep 30 '19 at 10:26
  • Oof. I had "XML documentation file" checked for my Debug config, but not my Release config. Guess which config I used for my Azure Devops build pipeline and couldn't figure out why the XML comments file wasn't being included in the built nuget artifact? :p – David Alan Condit Oct 30 '20 at 15:25