Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate documentation with DocFX using XML documentation file?

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?

like image 825
Baljeet Singh Avatar asked Dec 28 '18 23:12

Baljeet Singh


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.

What is XML documentation in C#?

XML Documentation helps other programmers or developers to use your code (classes, functions and their members) easily by providing some useful information. XML Documentation starts with three slashes before the class or function to be documented.

How do I use Docfx?

Use DocFX as a command-line toolDownload and unzip docfx. zip from https://github.com/dotnet/docfx/releases, extract it to a local folder, and add it to PATH so you can run it anywhere. This command generates a default project named docfx_project . Now you can view the generated website on http://localhost:8080.

How do I read XML documents?

You can view XML files in different ways including using a text editor, like Notepad or TextEdit, a web browser like Safari, Chrome, or Firefox, or an XML viewer. Open your text editor or XML viewer, then open your XML to view it. Drag and drop the XML file to your web browser to view it.


1 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.

like image 110
Konard Avatar answered Nov 04 '22 00:11

Konard