Building Sandcastle Documentation with Team Build

This post outlines how to configure Team Build, Sandcastle and the Sandcastle Help File Builder (SHFB) to generate MSDN-style documentation for assemblies.

Sandcastle produces accurate, MSDN style, comprehensive documentation by reflecting over the source assemblies and optionally integrating XML Documentation Comments. It is command line based and has no GUI front-end, project management features, or an automated build process like those that you can find in NDoc.

Sandcastle Help File Builder is a frontend for Sandcastle that provides graphical and command line based tools to build a help file in an automated fashion.

How it works

The usual way to configure SHFB is to open the GUI and create a SHFB project file from your solution file with your desired configuration. Then you’re supposed to check this file into source control and maintain it each time you add a new assembly.

This post outlines a possibly simpler approach – it uses a common SHFB project template file and passes the assemblies that Team Build generates as arguments to the SandcastleBuilderConsole.exe program. This means it automatically includes all assemblies that have been built.

Once the documentation has been built, it is copied to the Team Build drop location along with the binaries.

Sandcastle Team Build Target

Setup: TFSBuild.proj

To actually get Team Build to generate the documentation, we need override the GenerateDocumentation target and insert our new target into the project.

In source control, checkout the TFSBuild.proj file for your build definition and insert the following snippet at the end, just before the </Project> tag.

<Import  Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>


<Target Name="GenerateDocumentation">

  <PropertyGroup>

    <SandcastleBuidlerPath>C:\Program Files\EWSoftware\Sandcastle Help File Builder\SandcastleBuilderConsole.exe</SandcastleBuidlerPath>

    <SandcastleBuilderProjectTemplateFile>$(MSBuildExtensionsPath)\template.shfb</SandcastleBuilderProjectTemplateFile>

    <SandcastleBuilderProjectFile>$(MSBuildProjectDirectory)\project.shfb</SandcastleBuilderProjectFile>

    <SandcastleBuilderArguments>-assembly=&quot;$(OutDir)*.dll&quot; -outputpath=&quot;$(OutDir).&quot;</SandcastleBuilderArguments>

    <!-- -dependency=&quot;$(SolutionRoot)\References\*.dll&quot; -->

    <!-- HACK: For some reason the -outputpath argument requires a '.' on the end,

     otherwise you get BUILD FAILED: Illegal characters in path. -->

  </PropertyGroup>

 

  <Error Text="Sandcastle Help File Builder is not found at $(SandcastleBuidlerPath)." Condition="!Exists('$(SandcastleBuidlerPath)')"  />

  <Error Text="Sandcastle Help File Builder project template is not found at $(SandcastleBuilderProjectTemplateFile)."

         Condition="!Exists('$(SandcastleBuilderProjectTemplateFile)')" />

 

  <Copy SourceFiles="$(SandcastleBuilderProjectTemplateFile)" DestinationFiles="$(SandcastleBuilderProjectFile)" />

 

  <XmlUpdate XPath="/project/HelpTitle" XmlFileName="$(SandcastleBuilderProjectFile)" Value="Documentation for $(BuildDefinition)" />

  <XmlUpdate XPath="/project/HtmlHelpName" XmlFileName="$(SandcastleBuilderProjectFile)" Value="$(BuildDefinition)" />

  <XmlUpdate XPath="/project/FooterText" XmlFileName="$(SandcastleBuilderProjectFile)" Value="Build Number: $(BuildNumber)" />

 

  <Exec Command="&quot;$(SandcastleBuidlerPath)&quot; &quot;$(SandcastleBuilderProjectFile)&quot; $(SandcastleBuilderArguments)" />

 

</Target>

Configuration

Property Description Default
SandcastleBuidlerPath Path to SandcastleBuilderConsole.exe C:\Program Files\EWSoftware\Sandcastle Help File Builder\SandcastleBuilderConsole.exe
SandcastleBuilderProjectTemplateFile Path to the template SHFB project file created via the GUI $(MSBuildExtensionsPath)\template.shfb
SandcastleBuilderProjectFile Path to copy the template SHFB project file to, before modifying it for the current build $(MSBuildProjectDirectory)\project.shfb
SandcastleBuilderArguments Arguments to pass to SandcastleBuilderConsole.exe -assembly=&quot;$(OutDir)*.dll&quot; -outputpath=&quot;$(OutDir).&quot;

Build Server Setup

The following pre-requisite software is required for the build server:

Blocked CHM Help Files from a Network Share

Because the drop location is a network share, the viewing of CHM files is often blocked. This is because network shares fall into the “Intranet” security zone, which isn’t trusted.

There are two options for getting around this:

  1. Copy the documentation file to your local machine, right-click, select properties, select Unblock.
  2. Or disable blocking for the Intranet zone by creating the following registry key. (More information here)
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions]
"MaxAllowedZone"=dword:00000001

TODO

  • It may be necessary to cater for References or Dependent assemblies. This would be possibly via another command line argument and a <CreateItem> task to search $(SolutionRoot)\References\**\*.dll
  • Namespace documentation is usually configured via the SHFB project file, I haven’t covered this in this implementation.

More Information

7 Comments

  1. Posted February 20, 2008 at 2:30 am | Permalink

    Yeah, we’ve been doing this for some time now. Works pretty well. :)
    Not sure how we do it, it’s 2-3 months since I did this…

  2. Shabariji
    Posted February 26, 2008 at 9:47 pm | Permalink

    Hi Grant,
    I had been trying this customization from past few days using the info provided here: http://blogs.msdn.com/rimuri/archive/2006/10/30/reusable-msbuild-sandcastle-targets-file.aspx
    For reasons unknown had many problems in implementing it. Then i went through your blog and it works absolutely fine. Keep up the good work…
    -Shabariji

  3. Shabariji
    Posted May 29, 2008 at 8:15 pm | Permalink

    Hi Grant, just wanted another clarification from your side. I had tried this solution with TFS2008 team build, but when i used TFS2005 team Build the Target GenerateDocumentation never gets invoked or executed and the Build passes with a green signal, which made me think whether this solution works at all with TFS2005? With Sandcastle help file builder, the chm file is created, but when I invoke it from TFSBuild.proj is when am not getting any warnings or errors. Thanks a ton in advance for any inputs from your side.

  4. Ross
    Posted October 9, 2008 at 2:20 pm | Permalink

    Hi Grant, with your new website layout, a bunch of the TFSBuild.proj file is getting cut off. Any chance of fixing it?

    Thanks.

  5. Ross
    Posted October 9, 2008 at 2:23 pm | Permalink

    Never mind – I can get the full text by cut and pasting to a text editor.

  6. Posted March 29, 2009 at 5:36 am | Permalink

    I tried your solution but it didn’t work for me, Build failed. I guess I have to create a template somehow? Can you point me in the right direction on how to do that?

  7. Paul
    Posted April 15, 2009 at 1:53 pm | Permalink

    Any chance of updating this to utilize the latest Sandcastle version (where they moved all the files and changed all the names apparently)? I’m having trouble finding a good example of using team build and this latest version.


3 Trackbacks

  1. [...] Link to Building Sandcastle Documentation with Team Build « Grant Holliday [...]

  2. [...] Building Sandcastle Documentation with Team Build (Grant Holliday) [...]

  3. By Team System News : VSTS Links - 02/25/2008 on February 26, 2008 at 5:24 am

    [...] Holliday on Building Sandcastle Documentation With Team Build and Building A Release Notes Text File With Team [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*