How to generate documentation with DocFX using XML documentation file?

Viewed 4548

I want to create something like API documentation website for a .NET project. As per .NET Docs the XML comments that we put on top of methods, classes etc. can be processed into an XML file by the compiler and that file can be run through tools like DocFX to generate the documentation website. .NET Docs does not provide any instructions for the latter and DocFX documentation also does not give any hint on how to use that XML file to create API documentation website.

Any ideas on how can I use that XML file with DocFX to generate API Documentation Website?

2 Answers

If you are using .NET Core 2.2 or greater, you can update your docfx.json to directly extract metadata from .dll and .xml.

DocFX "will lookup for the XML file in the same folder" with the same file name as .dll.

Example:

{
  "metadata": [
    {
      "src": "bin/Release/netstandard2.0/YourCompany.YourNamespace.dll",
      "dest": "obj/api"
    }
  ]
}

You should also include <GenerateDocumentationFile>true</GenerateDocumentationFile> into your .csproj file.

For anyone stumbling across this, DocFX can be used from Visual Studio 2017 and later directly:

  • Install the docfx.console NuGet package to the project containing the XML documentation.
  • Upon building the project a _site folder will be generated in the same folder where the project's .csproj file resides. That folder contains the documentation (access via the index.html file).

Source: DocFX Documentation

Related