60

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.

1

2 Answers 2

82

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.

Sign up to request clarification or add additional context in comments.

2 Comments

But from what and where is this doc file going to be created? Where is that file/should be, where is the content?
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.
8

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>

2 Comments

If you remove the Condition attribute it will generate the XML file for all build configurations.
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.