Steve
Steve

Reputation: 1694

Show comments in nuget package

How do I include the comments that I write above my methods and properties in my nuget package? Ie. So when the library is consumed the user can use intellisense and read what the method is about?

eg. if I have the method

/// <summary>
/// This method does such and such
/// </summary>
public void SomeMethod()
{
   // does something..
}

Then I want to user to be able to see "This method does such and such" as they type the method.

Upvotes: 36

Views: 9565

Answers (2)

Tobias J
Tobias J

Reputation: 22823

In Visual Studio, right-click on the project, choose "Properties", then in the Build -> Output section of the Properties page, select the checkbox next to "Documentation file". Leave the file path empty so that it generates the file in the default location, which is where NuGet will expect it to be located.

Alternately, you can add the following to the .csproj file.

<PropertyGroup>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

Personally, I always put the above in a Directory.Build.props file in the root of the solution so that it's applied to all projects (I also put other common settings there like <TargetFramework> etc.).

In previous versions of .NET Core/VisualStudio, a bug caused the checkbox to store an absolute path to the documentation file which was obviously not ideal for teams. The bug is now be fixed as of version 16.9.

Upvotes: 44

CSharpie
CSharpie

Reputation: 9467

You have to enable the XML-Documentation when building.

See here

In Project-Properties go to the Build-Tab and select Xml-Documentationfile.

Looks similiar to this

German Version of Visual Studio

Upvotes: 20

Related Questions