To generate an XML documentation file from documentation comments in the code, use the /doc
option with the csc.exe
C# compiler.
In Visual Studio 2013/2015, In Project -> Properties -> Build -> Output, check the XML documentation file
checkbox:
When you build the project, an XML file will be produced by the compiler with a name corresponding to the project name (e.g. XMLDocumentation.dll
-> XMLDocumentation.xml
).
When you use the assembly in another project, make sure that the XML file is in the same directory as the DLL being referenced.
This example:
/// <summary>
/// Data class description
/// </summary>
public class DataClass
{
/// <summary>
/// Name property description
/// </summary>
public string Name { get; set; }
}
/// <summary>
/// Foo function
/// </summary>
public class Foo
{
/// <summary>
/// This method returning some data
/// </summary>
/// <param name="id">Id parameter</param>
/// <param name="time">Time parameter</param>
/// <returns>Data will be returned</returns>
public DataClass GetData(int id, DateTime time)
{
return new DataClass();
}
}
Produces this xml on build:
<?xml version="1.0"?>
<doc>
<assembly>
<name>XMLDocumentation</name>
</assembly>
<members>
<member name="T:XMLDocumentation.DataClass">
<summary>
Data class description
</summary>
</member>
<member name="P:XMLDocumentation.DataClass.Name">
<summary>
Name property description
</summary>
</member>
<member name="T:XMLDocumentation.Foo">
<summary>
Foo function
</summary>
</member>
<member name="M:XMLDocumentation.Foo.GetData(System.Int32,System.DateTime)">
<summary>
This method returning some data
</summary>
<param name="id">Id parameter</param>
<param name="time">Time parameter</param>
<returns>Data will be returned</returns>
</member>
</members>
</doc>