Building Sandcastle Documentation with Team Build
February 19, 2008 at 10:24 pm | In TFSBuild.com, Team Foundation Server |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.
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="$(OutDir)*.dll" -outputpath="$(OutDir)."</SandcastleBuilderArguments>
<!-- -dependency="$(SolutionRoot)\References\*.dll" -->
<!-- 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=""$(SandcastleBuidlerPath)" "$(SandcastleBuilderProjectFile)" $(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="$(OutDir)*.dll" -outputpath="$(OutDir)." |
Build Server Setup
The following pre-requisite software is required for the build server:
- Sandcastle Jan 2008 Release from Sandcastle project on Codeplex
- Sandcastle Help File Builder Installer from SHFB project on Codeplex
- Html Help Workshop from Microsoft HTML Help Downloads
- MSBuild Community Tasks MSI from http://msbuildtasks.tigris.org/
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:
- Copy the documentation file to your local machine, right-click, select properties, select Unblock.
- 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
- Sandcastle team blog
- Sandcastle on MSDN
- Sandcastle project on Codeplex
- Sandcastle Help File Builder project on Codeplex
- MSBuild Community Tasks (there is a documentation file in the download that describes all the tasks and syntax)
- MSDN: Customizable Team Foundation Build Targets
- Microsoft HTML Help Downloads
8 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

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…
Comment by Jarle Nygård — February 20, 2008 #
[...] Link to Building Sandcastle Documentation with Team Build « Grant Holliday [...]
Pingback by Building Sandcastle Documentation with Team Build « Grant Holliday « Noocyte’s Weblog — February 20, 2008 #
[...] Building Sandcastle Documentation with Team Build (Grant Holliday) [...]
Pingback by » Daily Bits - February 20, 2008 Alvin Ashcraft’s Daily Geek Bits: Daily links, development, gadgets and raising rugrats. — February 21, 2008 #
[...] Holliday on Building Sandcastle Documentation With Team Build and Building A Release Notes Text File With Team [...]
Pingback by Team System News : VSTS Links - 02/25/2008 — February 26, 2008 #
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
Comment by Shabariji — February 26, 2008 #
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.
Comment by Shabariji — May 29, 2008 #
Hi Grant, with your new website layout, a bunch of the TFSBuild.proj file is getting cut off. Any chance of fixing it?
Thanks.
Comment by Ross — October 9, 2008 #
Never mind - I can get the full text by cut and pasting to a text editor.
Comment by Ross — October 9, 2008 #