Jan Schreuder on .Net

.Net code samples, experiences, observations

View my professional profile on LinkedIn

Recent Posts

Tags

News

  • Inappropriate comments will be deleted at my discretion.

    The information and code samples in this weblog is provided "AS IS" without warranty of any kind, either expressed or implied, including but not limited to the merchantability and/or fitness for a particular purpose.

Community

Email Notifications

Tool suppliers

Tools

General

Microsoft

Favorite blogs

Archives

How to: Generate source documentation using Sandcastle

I've blogged about Sandcastle a few times already (see these links) in the past year. Sandcastle is the Microsoft solution for generating Help files using the XMl documentation tags in your .Net code. I've decided I needed to post an update on the current status of Sandcastle, because I feel the tool is getting more mature. At present, the March CTP has just been released.

The reason for this new post was the new CTP and the improved Sandcastle Helper by Eric Woodruff. The new CTP contains numerous fixes. A large number of these fixes are related to the Orcas Beta 1 release. Sandcastle now supports building help files based on Orcas projects and correctly references Orcas assemblies.

The Sandcastle Helper is, by my opinion, still one of the better options to create a help file using Sandcastle. At first, the application featured only a Winforms GUI application which strongly resembles the infamous (but now deceased) NDoc application. There is now also a console application which uses the project files that you create using the GUI application. This gives you the option of including it in a postbuild event in your Visual Studio project. The application also helps you add references to GAC assemblies you use in your solution. Sandcastle needs these references so that reflection will help extract information about objects used from these GAC assemblies.

In this post I will try to give you a short introduction for when you want to use Sandcastle and the Sandcastle Helper.

Quickstart

So let's have a quick look in how you can use Sandcastle for generating your documentation. You must first install the CTP and the Sandcastle Helper:

Step 1 - Make sure the project creates an XML document

Now let's assume you have a .Net assembly called ClassLibrary1 which contains the following sample class:

using System;
using System.Collections.Generic;
using System.Text;
 
namespace ClassLibrary1
{
    /// <summary>
    /// A sample class to show something using Sandcastle
    /// </summary>
    public class SampleClass
    {
        private string _propertyValue;
 
        /// <summary>
        /// Gets or sets the property value.
        /// </summary>
        /// <value>The property value.</value>
        public string Property
        {
            get
            {
                return _propertyValue;
            }
            set
            {
                _propertyValue = value;
            }
        }
 
        /// <summary>
        /// Determines whether the property is null.
        /// </summary>
        /// <returns>
        ///     <c>true</c> if property is null; otherwise, <c>false</c>.
        /// </returns>
        public bool IsPropertyNull()
        {
            bool result = false;
 
            if (this.Property == null)
            {
                result = true;
            }
            return result;
        }
 
        /// <summary>
        /// Determines whether the property is null.
        /// </summary>
        /// <returns>
        ///     <c>true</c> if property is empty; otherwise, <c>false</c>.
        /// </returns>
        /// <example>
        /// This example shows how you might use this method:
        /// 
        /// <code>
        /// SampleClass sample = new SampleClass();
        /// 
        /// if (sample.IsPropertyEmpty())
        /// {
        ///        Console.WriteLine("The property is empty");
        /// }
        /// else
        /// {
        ///        Console.WriteLine("The property contains value " + sample.Property);
        /// }
        /// </code>
        /// </example>
        public bool IsPropertyEmpty()
        {
 
            bool result = this.IsPropertyNull();
 
            if (!result)
            {
                result = (Property.Trim().Length == 0);
            }
            return result;
        }
    }
}

Never mind rather silly looking code, it's just to demonstrate Sandcastle ;-). I'm assuming everybody knows this, but make sure you check the XML documentation file check box on the Build tab in your project properties window:

Step 2 - Compile the assembly 

Now compile the class library. You should see the ClassLibrary1.XML in the Debug directory.

Step 3 - Run the Sandcastle Help File Builder

Next thing to do is start the Sandcastle Help File Builder. You should see the following window:

Step 4 - Add assemblies to the Sandcastle Help File Builder project 

To create a help file, all you need to do now is click the Add button and select the compiled assembly for the class library. The Assemblies to Document list box should then show the assembly you compiled, and the XML file containing the documentation information that the .Net compiler extracted from your code.

Step 5 - Set additional properties

In the Project properties panel of the application you should change the following properties:

  • Presentation Style. Set this to VS2005
  • SDK Link type. Set this to Index
Step 6 - Generate the help file

Last step is to click on the generate button in the toolbar:

The application will then run all Sandcastle tools in the correct order to generate a help file.

Step 7 - View generated help file

When the help file is compiled, you can view the result by selecting View Help File from the Documentation menu. The documentation for the method IsPropertyEmpty in the above sample class will look like this:

Comments

Robin Paardekam said:

Thanks Jan, this is very helpful.
# June 6, 2007 2:49 PM

Jscript said:

Hi Am try to create Document for JavaScript

Using Script Doc I creatd ORG(*.org) as well as (*.xml)

But i do not know how to generate Document using SandCastle ?

pls give any useful idea

# August 14, 2007 12:46 PM

Jan Schreuder said:

You should check out the Sandcastle blog (blogs.msdn.com/sandcastle) and in particular this post: blogs.msdn.com/sandcastle/archive/2007/06/28/scriptdoc-1-0-for-extractiong-javascript-code-comments-is-now-available-at-codeplex.aspx

It describes a tool which you can use to extract comments for JavaScript.

# August 14, 2007 4:57 PM

Javier said:

Regards,

I am using the Sandcastle Help File Builder v1604, Sandcastle January release 2008 and HTML Help WorkShop v1.3, and create a document in chm, my problem is that creates my file output class.chm without problem, but on having opened, I see the namespace, the methods, etc, but do not see your description, is empty. I need to solve urgently this problem, please help me.

Thanks,

Javier

# March 31, 2008 9:24 PM

Sangram said:

Hi,

I just want to know  the comments ///.... are essential for the sandcastle to understand or can i use

/*

<summary> some description </summary>

*/

instead

/// <summary>

/// some description

//</summary>

I have tried with the first one but it is giving me error as

D:\ProgramFiles\Sandcastle\Examples\sandcastle>csc /t:library /doc:comments2.xml test.cs

Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42

for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727

Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

test.cs(18,18): warning CS1591: Missing XML comment for publicly visible type or member 'TestNamespace.StoredNumber'

D:\Program Files\Sandcastle\Examples\sandcastle>

# May 8, 2008 9:22 AM

Karl Proctor said:

Excellent article. This was just what the doctor ordered. Worked first time, and allowed me to integrate into the project I was working on.

Thanks

# August 4, 2008 4:22 PM

cebastos said:

how can I generate description information into the generated .chm file?

[source code]

/// <summary>

/// Gets a value that is used to convert twips to pixels based on screen settings.

/// <returns>The conversion factor.</returns>

/// </summary>

public float TwipsPerPixelY

[generated information]

Name Description

TwipsPerPixelY    - an empty description -

# November 17, 2008 10:08 PM

Writer4Geeks said:

I need to document web services and xml schemas.

Any suggestions?

# December 16, 2008 12:38 AM

Ankush Bindlish said:

Hi,

I need to make it running inside the build script. What would be the SandcastleBuilderConsole.exe parameters?

# January 12, 2009 9:56 AM

Jan Schreuder said:

Not sure. But why not check out the forum at the CodePlex or switch to DocProject. DocProject allows you to create a .Net project inside your solution and generate the documentation from inside Visual Studio. And since it is a .Net project, you can simply build the project created using a build script.

# January 13, 2009 2:14 PM

Ryan said:

Thank goodness for your article.  I could not for the life of me figure out how to make these tools work.  You are a God-send! :)

# March 7, 2009 12:09 AM

Jose Escalona said:

great article !! great explanation, it worked at the first try, thanks!

but in case of web projects or web services how it works?

# April 21, 2009 2:34 AM

Narendra said:

Greate it really works !

# May 15, 2009 2:17 PM

Vijay said:

Thank a lot... for an wonderful article.  

# May 27, 2009 1:23 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Please add 7 and 7 and type the answer here: