Click here to Skip to main content
Click here to Skip to main content

Documentation of .NET Class Libraries using NDoc

, 6 Jan 2008
Rate this:
Please Sign up or sign in to vote.
This article explains how to use NDoc for documenting .NET class libraries.

Introduction

API documentation of an application is one of the most tedious tasks for all developers. NDoc makes it very easy for everyone. In this article, I will try to explain how we can use NDoc to generate MSDN style documentation for your class libraries.

Background

NDoc generates class libraries documentation from .NET assemblies and the XML documentation files generated by the C# compiler (or an add-on tool for VB.NET such as VBCommenter).

NDoc uses add-on documenters to generate documentation in several different formats, including the MSDN-style HTML Help format (*.chm), the Visual Studio .NET Help format (HTML Help 2), and MSDN-online style Web pages.

The NDoc source code is available under the GNU General Public License. If you are unfamiliar with this license or have questions about it, here is a FAQ.

Using the Code

You can download the NDoc utility files from SourceForge.Net. Now open the solution for which you want to generate documentation in Visual Studio 2005. Add a sample class library to test or you can use any existing one. Select the class library for which you want to create documentation. Right click on it and click on “Properties”. You will see the following dialog box.

Property Screen

Now click on the ‘Build’ tag.

Build Config Screen

You will see one check box “XML documentation file:” (See the red eclipse part above). Just enable that check box and specify a name for a *.doc file. NDoc uses this file for creating documentation.

Now build your class library. Just check the Debug/Release folder (depends on your build configuration). You will see the documentation file in XML format. NDoc’s help will give you a brief idea about how you can document your class library more effectively.

Here are some tips from NDoc’s documentation:

  1. The more code comments you add to your code, the more descriptive the generated help topics will be.
  2. At a minimum, each public type and the public and protected members of your public types should have an item describing what the member does or represents. The VS.NET C# code editor has a handy feature that makes it easy to create the basic code comments for each type and member.
    For the following code snippet:

    public class MyClass() {
    public MyClass( string s ) { }
    }

    If you place your cursor just above the MyClass constructor, and hit the '/' character three times in a row, VS.NET will create the skeleton of a code comment block for that member:

    public class MyClass() {
    /// <span class="code-SummaryComment"><summary></span>
    ///
    /// <span class="code-SummaryComment"></summary></span>
    /// <span class="code-SummaryComment"><param name="s"></param></span>
    public MyClass( string s ) { }
    } 

    This applies to any type or member that can have code comment tags associated with it. Moreover, once you have a code comment block, when you hit the '<' key to start a new tag, VS.NET will display an intellisense selector showing the appropriate list of code comment tags. Unfortunately this list won't include the additional tags that NDoc supports, but you can still add them manually.

NDoc supports a large number of documentation tags. You can use it as per your requirement.

Ok… so your project is now ready for documentation. Now just unzip the NDoc file which you have already downloaded from SourceForge.net. I have this version ndoc-bin-1.3.1-v16.zip. Browse the unzipped archive and locate file NDocGui.exe. This gives a better GUI to use NDoc. The same folder contains the command line utility NDocConsole.exe. We can use the command line utility for the automated build process. In this article, I am going to explain the GUI utility only. Double click on NDocGui.exe. You will see the NDoc GUI console.

NDoc GUI Screen

Click on Project->New. Notice the “Select and Configure Documenter” section. Here you can specify the output documentation type. NDoc can generate a document in various formats like MSDN, Linear HTML, JavaDoc etc. Select MSDN for now. Below that you can see various options to configure your documentation output like Copyright text, Output directory etc. The most important settings are in the visibility section. Just check which elements you want to document. For example, private variables, protected variables, Namespaces without summaries etc. (Check out the red eclipse in the following image.)

visibility option

Now click on Add.
This will open up the following dialog box.

add assembly

You will see a small command button to specify a value for the key "Assembly" through which you can browse for your assembly path. Select the EXE/DLL file of your application which you want to document.
NDoc will automatically take an XML documentation file as per the selected EXE or DLL file.
Now save the NDoc project file somewhere. So next time if we modify the source, we can open the saved project in NDoc and then we can do the documentation build again.
Now Build the file. You can see the Build button on the left upper corner of the screen shown below. Click on it.

Build Button

All build messages will appear in the “Output” section of the GUI console. You will see the last message as given below:

Created c:\Documents and 
  Settings\vinayakc\Desktop\New Folder\doc\ndoc_msdn_temp\Documentation.chm, 57,879 bytes
Compression decreased file by 238,719 bytes.

Html Help compile complete
Done.

Now check the output directory specified in the output message. You will find the *.chm file there which will be the compiled documentation for your class library. Just double click it and enjoy your application’s professional documentation.
Happy coding!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

VinayakChitre
Software Developer Covelix Technologies, Pune, India.
India India
5+ years of technical experience.
 
Completed graduation from Govt. Engineering college, Pune.
Working as SW developer in Covelix for more than 3 years.
 
My technical experience includes n-tier applications in .NET, MFC | C, C++, C#, Python | SQL server, Oracle 10g | AJAX | Installsheld.

Comments and Discussions

 
GeneralAlternative PinmemberBarry Jones27-Jul-10 0:59 
Generalvisual studio 2008 Pinmembermusabyildiz8-Mar-10 21:22 
QuestionNDoc syntax highlighting for CODE block (tag) Pinmemberaphazel15-Nov-09 23:54 
GeneralAble to generate the Documentaion using Ndoc Pinmembersathishkumar_rs12-Feb-09 23:26 
GeneralNice try, but the NDoc project is dead... PinmemberJuergen Posny7-Jan-08 3:28 
GeneralRe: Nice try, but the NDoc project is dead... PinmemberFernando A. Gomez F.7-Jan-08 7:16 
There was a workaround library somewhere out there that allowed generics to be documented, and I used it until Sandcastle arrived. Now I can't find it anymore... But yes, I agree, Sandcastle with the Helpfile Builder are the best option now.
 

Stupidity is an International Association - Enrique Jardiel Poncela

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140826.1 | Last Updated 7 Jan 2008
Article Copyright 2008 by VinayakChitre
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid