简体   繁体   English

如何使用XML文档文件通过DocFX生成文档?

[英]How to generate documentation with DocFX using XML documentation file?

I want to create something like API documentation website for a .NET project. 我想为.NET项目创建类似API文档的网站。 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 ,我们在方法,类等之上添加的XML注释可以由编译器处理为XML文件,并且可以通过诸如DocFX之类的工具运行该文件以生成文档网站。 .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. .NET Docs没有为后者提供任何说明,并且DocFX文档也没有提供有关如何使用该XML文件创建API文档网站的任何提示。

Any ideas on how can I use that XML file with DocFX to generate API Documentation Website? 关于如何将XML文件与DocFX一起使用以生成API文档网站的任何想法?

For anyone stumbling across this, DocFX can be used from Visual Studio 2017 and later directly: 对于任何遇到此问题的人,都可以在Visual Studio 2017和更高版本中直接使用DocFX:

  • Install the docfx.console NuGet package to the project containing the XML documentation. docfx.console NuGet软件包安装到包含XML文档的项目中。
  • Upon building the project a _site folder will be generated in the same folder where the project's .csproj file resides. 构建项目后,将在项目的.csproj文件所在的同一文件夹中生成_site文件夹。 That folder contains the documentation (access via the index.html file). 该文件夹包含文档(可通过index.html文件访问)。

Source: DocFX Documentation 资料来源: DocFX文档

If you are using .NET Core 2.2 or greater, you can update your docfx.json to directly extract metadata from .dll and .xml . 如果您使用的是.NET Core 2.2或更高版本,则可以更新docfx.json以直接从.dll.xml提取元数据。

DocFX "will lookup for the XML file in the same folder" with the same file name as .dll . DocFX “将在同一文件夹中查找XML文件” ,其文件名与.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. 您还应该将<GenerateDocumentationFile>true</GenerateDocumentationFile>.csproj文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM