Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include XML documentation file in NuGet package built from a project file?

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.

like image 442
ChaseMedallion Avatar asked Feb 07 '18 12:02

ChaseMedallion


People also ask

How do I create an XML document in Visual Studio?

From the menu bar, choose Tools > Options to open the Options dialog box. Then, navigate to Text Editor > C# (or Visual Basic) > Advanced. In the Editor Help section, look for the Generate XML documentation comments option.

Where are NuGet packages references stored?

Today, a project's NuGet package information is stored in a project-level packages. config folder. The assemblies are stored in a separate packages folder, usually at the solution level.


2 Answers

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.

like image 154
Martin Ullrich Avatar answered Sep 22 '22 13:09

Martin Ullrich


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> 
like image 22
Bartosz Avatar answered Sep 24 '22 13:09

Bartosz