|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Table of Contents
IntroductionSandcastle is the tool used for creating MSDN-style documentation from .NET assemblies and their associated XML comments files. The current version is the March 2007 CTP. It is command line based and has no GUI front-end, project management features, or automated build process that you can find in NDoc. I created the Sandcastle Help File Builder to fill in the gaps and provide some of the missing NDoc-like features that I use most often, as well as provide graphical and command line based tools to build a help file in an automated fashion.The project is hosted at CodePlex in the Sandcastle Help File Builder project. Go there for the latest release, source code, the issue tracker, and discussion boards. Using the help file builder provides the following advantages:
See the help file supplied with the help file builder for more information on how to use it. A FAQ is included in the help file that should answer most of the common questions and provide solutions to most of the common issues encountered by users of the help file builder. An Overview of the Help File Builder GUITo install the help file builder, download the MSI file using the link at the top of the article and run it. It will create a folder and a shortcut to the GUI tool in the Start | Programs menu. See the supplied help file for information on getting started, links to required resources and other information, setting up your projects to generate XML comments, creating a new help file builder project, common problems and solutions, and expanded information on topics found in this article. When the help file builder is ran, the following window appears. The main form has intentionally been designed to look and function as much like NDoc as possible. The toolbar contains most of the common functions. A Save Project As option, a New Project from NDoc Project option, a New Project from Visual Studio Project option, and a list of the most recently opened projects is also available on the Project menu. The help builder will automatically load the last used project when opened.![]() The top part of the form contains a list box showing the list of assemblies that will be documented. The entries display the assembly name and the XML comments filename. The three buttons to the left of the list allow you to do the following:
See the Project and Namespace Summaries topic for information on setting the project and namespace level summary text and how to limit which namespaces are documented. NOTE: Only add assemblies and XML comment files that you want documented in the top section. Third-party assemblies, interop assemblies, and other dependent DLLs should be added to the project's The center section of the form contains a property grid that displays the project options. The options are grouped into several categories and are listed alphabetically within them. More information on the properties can be found in The GUI Project Manager section. The bottom section of the form contains an output window that will display the messages from the build process. The View Output in Window option on the Documentation menu will open a resizable window that can be used to more easily view the build log output. Absolute and Relative PathsIn the form that lets you edit the assembly and XML comment filenames and for the path-related properties in the project, you can enter absolute paths or relative paths. When using the designer popups (accessed by clicking the "..." button to the right of the filename/folder value in the property grid when it is selected), absolute paths are always returned. However, you can edit the returned path to make it a relative path. The key point to remember is that the help file builders (both the GUI and console version) always expect that relative paths are relative to either the folder in which the project file is saved or to the working folder used for the build. The expected relative location will be noted in the description of each affected property. A typical folder layout is shown here:C:\HelpTest\ Solution folder.
|
+-TestAssembly Application project folder.
| |
| +-Bin
| |
| +-Release Location of assembly and comment files.
|
+-Doc Help file builder project location.
|
|
+-Help The output folder for the help file.
|
+-Working The intermediate working folder used
| during the build.
|
+-DLL Dependencies folder for MRefBuilder
| (if needed).
|
+-Output Help file project compilation folder.
+-art
+-html
+-scripts
+-styles
The example above places the help file builder project in the C:\HelpTest\Doc\ folder. As such, the relative path to the assembly that will be documented and its comment file is ..\TestAssembly\Bin\Release\. The default output folder for a project is always .\Help\. If you would prefer the help file to end up in a different location, you can modify it using the OutputPath property.
Project SummaryThe Prj Summary button in the Assemblies to Document section of the main form opens a form in which you can enter summary comments that should appear in the root namespaces page of the compiled help file. This is the standard default page unless additional content is defined that is marked as the default page. The Namespaces page is also accessible via the breadcrumb link available at the top of the namespace item help pages in the generated help file. These comments will appear above the list of namespaces and can contain HTML markup (i.e. text formatting, e-mail links, etc). If none are defined, the page just shows the list of namespaces.Namespace SummariesThe Namespaces button in the Assemblies to Document section of the main form allows you to specify which namespaces should appear in the help file and the namespace summaries to display in the root namespaces page and on the help page for each namespace.![]() Check the namespaces that you want to appear and uncheck those that you do not want to appear. By default, all namespaces in all assemblies are documented with the exception of the global (unnamed) namespace that sometimes appears and contains private module details. To edit a namespace summary, select the namespace in the list and edit the comments in the text box at the bottom of the form. The comments can include HTML markup (i.e. bolding, e-mail links, etc). If no summary is defined, a red warning note will appear for the namespace on the root namespaces page and above the namespace content in the help page for the namespace itself. When this form is opened, it scans the documentation assemblies for new namespaces and adds them to the list if it finds any. If you build a help file without updating the namespace list, any unknown namespaces will appear in the help file but they will also contain a red warning message indicating that the namespace summary is missing. Namespaces are never removed from the list even if the namespace no longer appears in one of the documented assemblies. You can remove old namespaces from the list by selecting them and clicking the Delete button. The Path Category PropertiesThe following properties are available in the Path category. These define the location of the tools and the output location of the help file.HtmlHelp1xCompilerPathThis property lets you specify the path to the HTML 1.x help compiler (HHC.EXE). By default, the builder will try to locate it automatically by searching the Program Files special folder on all fixed hard drives. As such, you only need to specify the path if the build fails with a message stating that it could not be found.HtmlHelp2xCompilerPathThis property lets you specify the path to the HTML help 2.x compiler (HXCOMP.EXE). By default, the builder will try to locate it automatically by searching the Program Files special folder on all fixed hard drives. As such, you only need to specify the path if the build fails with a message stating that it could not be found.OutputPathThis property lets you specify where the compiled help file should be placed. The default is to store it in a folder called .\Help\ relative to the project folder. It is also the location of the temporary .\Working\ folder used to store the generated build files unless it is changed with theWorkingPath property.
SandcastlePathThis property lets you specify the path to Sandcastle. By default, the builder will try to locate it automatically by extracting its location from the system path and, if not found there, by searching the Program Files special folder on all fixed hard drives. As such, you only need to specify the path if the build fails with a message stating that it could not be found.WorkingPathThis property lets you specify an alternate location with a shorter path in which to perform the build if it fails due to long file path names. If not specified, the working folder will be placed under the output path and will be called .\Working.The Build Category PropertiesThe following properties are available in the Build category. These control the build process.CleanIntermediatesThis property is used to specify whether or not intermediate files created during the build are kept after a successful build or are purged. The default is true to purge the files. If not purged, you will find the files in a .\Working folder under the project's output path folder. Files that are placed there include the build scripts, configuration files, and the HTML help compiler project output files (scripts, art, HTML pages, the HTML help project, etc). The intermediate files are always retained if the build fails so that you can examine them to find the cause if necessary.ComponentConfigurationsThis option allows you to configure build components that support the Sandcastle Help File Builder's plug-in method to interactively set their options. See the Custom Build Components topic for information on the ones supplied with the help file builder.DependenciesThis property can be used to specify a list of dependent assemblies and/or folders containing dependent assemblies for use by the MRefBuilder tool when it generates reflection information for the documentation assemblies. Currently, MRefBuilder does not resolve references to all assemblies used by a target, especially those found in the Global Assembly Cache (GAC). As such, it needs a pointer to find the files and load them when needed (the /dep command line option). This property uses a collection editor that lets you choose folder paths, individual files, or GAC references to define the dependencies.
By specifying the dependent assemblies or the folders containing them, the build process can create a folder containing the dependencies for MRefBuilder to use. Paths to the assemblies can be absolute or relative. Relative paths are assumed to be relative to the project folder. In addition to file and folder dependencies, you can also select assemblies from the GAC. This is useful in situations where an assembly only appears in the GAC and does not have an easily located copy elsewhere on disk. Entries selected from the GAC are prefixed by the identifier "GAC:" and show the fully qualified name rather than a file path. At build-time, the GAC is queried and the necessary assemblies are copied from it to the dependencies working folder. FrameworkVersionThis property allows you to specify to which .NET Framework version the documentation links for system types should point. The default is to use the most recent .NET version available on the system (currently 2.0.50727). In theory, it is possible to also use Sandcastle to produce help files for .NET 1.1 assemblies. I have not had a chance to confirm that this property actually works as expected. I will provide more details about this property once I have had a chance to test it more thoroughly.HelpFileFormatThis property lets you specify the type of help file to build (HTML Help 1.x, HTML Help 2.x, a website, or various combinations of the three options). The default is to produce an HTML Help 1.x format file.Be aware that if an option is selected that produces a website, the output folder will be cleared of all of its current content before the web site content is copied to it. When producing a help file alone, the output folder is not cleared. When producing a website, the following additional files are copied to the root of the output folder.
PurgeDuplicateTopicsThis property is present to fix a bug that I ran across. When generating documentation into one help file for multiple assemblies that contain one or more common classes compiled into each of them, you end up with duplicate entries in the table of content and help entries for the common classes. You also get duplicate entries in the namespace help page for each namespace associated with the common classes. To fix this for problem for now, I added this property that causes the builder to strip out duplicate properties from the reflection.org file generated by MRefBuilder. It is set to true by default. If you think it may be causing problems, set it to false. If this is fixed in a later CTP, I will remove this option.The Help File Category PropertiesThe following properties are available in the Help File category. These control the appearance and features of the generated HTML help file.BinaryTOCWhen set to true, the default, a binary table of contents is created for the help file. According to the HTML Help Compiler documentation this can significantly reduce the amount of time required to load a very large help document.CopyrightHref and CopyrightTextThese two properties can be used individually or in combination. If onlyCopyrightHref is specified, a link will appear in the footer of each page for the specified URL. If only the CopyrightText property is specified, that message appears in the footer of each page. If both are specified, a link appears in the footer of each page using the text from the CopyrightText property and the target of the link is set to the URL specified in the CopyrightHref property. See the Customizing the Header and Footer Text section for information on how to change the layout of this text.
The value of the FeedbackEMailAddressIf an e-mail address is specified in this property, an extra message is included in the footer of each page with a message saying "Send comments on this topic to" plus the specified e-mail address. The e-mail address is rendered as a click-able mailto: link. See the Customizing the Header and Footer Text section for information on how to change the layout of this text.FooterTextThis property can be used to insert an extra message in the footer of each page. By default, it is blank. HTML tags are supported within the text. See the Customizing the Header and Footer Text section for information on how to change the layout of the footer section.HeaderTextThis property can be used to insert an extra message in the header of each page. By default, it is blank. HTML tags are supported within the text. See thePreliminary property for a way to mark all topics as preliminary. See the Customizing the Header and Footer Text section for information on how to change the layout of the header section.
HelpTitleThis property is used to set the title for the help file. This text will appear as the title of the help file's window.HtmlHelpNameThis property is used to specify the name of the HTML help file. This name is used during the build process for a couple of other files so be sure that you do not specify a path or an extension on this value. It should only specify the name part of the file. The extension will always be .CHM and the path is controlled via theOutputPath property.
IncludeFavoritesIf this property is set to true, a Favorites tab will be included in the compiled help file. By default, it is set to false and only the Table of Contents and Search tabs are available.LanguageThis property allows you to specify the language to use for the compiled help file. The default is to use the English language resource files. Currently, language resource files are also available for German, French, Spanish, Italian, and Russian. If you specify any other language, the help file will build but you will see a warning in the build output that the selected language resources could not be found and that it is defaulting to the US English (en-US) language files. For more information on creating additional language resource files, see the help file topic by that name. If people are kind enough to supply additional translated files, I will add them in later releases.NamingMethodThis property allows you to specify how the help topics filenames will be generated. There are three separate options:Guid, MemberName, and HashedMemberName. See the help file for full details on the benefits of each naming method.
PreliminaryWhen this property is set to true, it will mark all topics in the help file with a large, red message "[This is preliminary documentation and is subject to change.]". This is a quick and easy way to mark documentation for beta software as preliminary and subject to change. See the Customizing the Header and Footer Text section for information on how to change the layout of this text.PresentationStyleThis property is used to choose the presentation style that determines the layout and appearance of the help topics. Sandcastle comes with two styles: Prototype (the default) and VS2005. The files for each style are located in the .\Presentation folder under the main Sandcastle installation folder. If you create your own styles, place the folders in the same location and the help file builder will detect them automatically and let you select them in the project.ProjectLinkTypeThis property is used to define the type of links used to reference other help topics referring to items within the documented assemblies. It can be set to None which renders non-clickable links, Local (the default) which renders normal links defined with anchor tags, or Index which renders HTML 2.x style MS-Help links. The Index option is only useful when generating an HTML 2.x help file.RootNamespaceContainerThis property is used to specify whether or not a root namespace entry is added to the table of content to act as a container for the namespaces from the documented assemblies. If true, a root Namespaces table of content entry will be created as the container of the namespaces in the documented assemblies. If false, the default, the namespaces are listed in the table of content as root entries.SdkLinkTypeThis property is used to define the type of links used to reference other help topics referring to framework (SDK) help topics. It can be set to None which renders non-clickable links, Index which renders HTML 2.x style MS-Help links, or MSDN (the default) which renders links to the online MSDN help content for the topic. The Index option is only useful when generating an HTML 2.x help file.SyntaxFiltersThis property lets you specify which languages appear in the Syntax section of the help topics and, for the Prototype presentation style, the dropdown in the upper right of the topics. It can be set toCSharp, VisualBasic, CPlusPlus, JSharp, a combination of those values, All to include them all, Standard (the default) for C#, VB.NET, and C++ only, or to None to remove the Syntax section entirely.
The Show Missing Tags Category PropertiesThe properties in the Show Missing Tags category define for which help topic elements a red "missing" message will appear if the related tag has not been used where needed or contains no text. These can help you locate help topics that need additional work to fully specify the documentation. In addition to the inserted messages, a warning is written to the log file noting the missing item as well. The following options are available:
The Visibility Category PropertiesThe properties in the Visibility category control what appears in the help file and can reduce the help content and get rid of unwanted items, especially when documenting internal and private members. The following items can be included or excluded from the help file.
The Additional Content PropertyTheAdditonalContent property is similar in nature to the NDoc properties AdditionalContentResourceDirectory, FilesToInclude, RootPageFileName and RootPageTOCName. However, the help builder's implementation provides the following added benefits over NDoc:
![]() The list box on the left lists the additional content. The property grid on the right lists the properties for the selected entry. The buttons below the list box allow you to:
The Destination PathFor additional content files, theDestinationPath property, if specified, will always be a relative path. When creating the help file content, an .\Output folder is created below the working folder to contain the art, scripts, style sheets, and HTML pages for the content. Additional content will also be placed in this folder. For entries without a destination path, they will be placed directly in the .\Output folder. For entries with a destination path, the content will be copied to the named folder beneath the .\Output folder. Any sub-folders beneath the source path folder will also be copied to the destination path recursively. The destination path name can be different from the source path if you want.
Defining the Table of Content LayoutAll HTML files copied as additional content will automatically be added to the help file's table of content. When the sub-folders of "*.*" wildcard entries are copied that contain HTML files, the sub-folders will also create folder entries within the table of content and the HTML files within them become children of the folder entry in the table of content. This makes it fairly simple to create hierarchical content with matching table of content entries. The table of content will mimic the folder structure on disk.The help file builder scans each HTML file for several tags and specially formatted comments that allow you to define the title and sort order of the table of content entries as well as which one should be the default topic. The tags can be added to the files manually or you can use the Preview option to visually arrange the items and set the default topic. See the help file for more details. Linking to Namespace ContentThe additional content help text may need to link to other topics in the help file such as help pages for a namespace, class, method, property, etc. To provide this ability, the help file builder will scan each HTML additional content file for XML comment style<see> tags. If found, an attempt is made to convert the tag to a link that takes you to the related help page for the indicated item.
Messages are written to the log file indicating how the link was resolved. If no matches are found, a message appears in the log stating that the identifier could not be found and it will be rendered in bold rather than as a link in the help file as is the case with the second example. If a single best match is found, the log message indicates the fully qualified name that was matched and the tag is converted to a link to the associated page in the help file. If multiple matches are found, the log will include a list of all fully qualified names that contained the identifier and the first entry found will be used as the target of the hyperlink. Syntax Highlighting <pre> Tag ContentThe help file builder allows you to add custom attributes to the<pre> tags in additional content HTML files to specify how the text should be colorized. The same attributes defined for the code block component can be used on <pre> tags with the exception of the source and region attributes. For the remaining attributes, the lang attribute must appear or they will be ignored. See the Code Block Component help topic for details.
Replacing Stock ContentAnother benefit of the additional content implementation is that it is possible to replace the stock content that appears in each help file. The stock content is copied from the Sandcastle installation folder and consists of the following:
SourcePath: Styles\presentation.css DestPath: Styles\ The ContentPlacement PropertyTheContentPlacement property allows you to define where the additional content items appear in the table of content. By default, they will appear above the namespaces. By setting this property to BelowNamespaces, you can make the items appear below the namespace entries in the table of content.
Creating Language Resource FilesThe language resource files are located in a sub-folder beneath the .\LanguageResources folder in the installation location for the Sandcastle Help File Builder. The sub-folders are named using the value returned by theCultureInfo.Name property (i.e. en-US, fr-FR, de-DE). There are three XML files:
How the files are encoded is very important if they contain extended characters. To ensure that the help file builder and the Sandcastle tools properly interpret the encoding within the files, it is best to save the files such that they contain byte order marks at the start of the file for Unicode encoded formats as well as an XML header tag that specifies the correct encoding. In the absence of byte order marks, the encoding in the XML header tag ensures that the file is still interpreted correctly. The supplied default language resource files contain examples of this. When using entities to represent special characters in the XML language resource files or in the header text, copyright text, etc, use the numeric form rather than the name form as the XML parser will not recognize them and will throw an exception. For example, if you specify Customizing the Header and Footer TextThe text for the preliminary documentation warning, header text, footer text, feedback e-mail note, and the layout of the copyright text can be customized by modifying the entries in the shared_content.xml file. Note that this file is language-specific and you will have to modify the entries for each language that you support. The following entries are available:
Building a Help FileTo build a help project using the GUI help builder, simply select the Documentation | Build Project menu option or click the toolbar button. For new projects, you are asked to save the project first so that the build process can determine the correct project folder location for use in resolving relative paths. The build process runs on a background thread and displays output as it progresses in the textbox at the bottom of the form. You can cancel a build by selecting the Documentation | Cancel Build menu option or by clicking the toolbar button.Once a build has finished, you can use the Documentation | View Output in Window menu option or toolbar button to view the build process output in a resizable window which makes it easier to see more information. Selecting the Documentation | View Help File menu option or toolbar button will allow you to view the resulting help file after a successful build. The help file and the log file can be found in the folder specified in the project's Setting Up Visual Studio to Open a Project FileThe help file builder project can be added to the solution file so that it can be checked into source control or opened from within Visual Studio. I like to add it as a solution item by right clicking on the solution name in the Solution Explorer, selecting Add | Existing Item, and then selecting the help file builder project. It is then added to a Solution Items folder in your solution. You can also have Visual Studio open the help file builder project using the GUI tool rather than its default text editor. To do so, right click on the help file builder project and select Open With.... Click Add to add a new program to the list. Enter the path to SandcastleBuilderGUI.exe for your system and enter something like "Sandcastle Help File Builder" for the friendly name. Click OK to save it, and then click Set as Default to make it the default tool for opening the help file builder projects. Click OK to save it. Now, whenever you double-click the help file builder project, it will open in the GUI tool automatically. Console Mode BuilderTo build a help project using the command line tool, run the SandcastleBuilderConsole.exe executable that can be found in the installation folder. In its simplest invocation, it takes one or more project file names to build and an optional /v option as command line parameters. The /v option will display all messages from the tools during the build process. If not specified, only the build step indicators are displayed on screen during the build process. In either case, full output is always saved to the log file. As with the GUI builder, the help file and the log file can be found in the folder specified in the project'sOutputPath property after a build.
Specifying a Post-Build Event to Build a Help FileTo use the console version in a post-build event of a Visual Studio project, right click on the project name in the Solution Explorer, select Properties, and select the Build Events sub-item. Click in the Post-build Event Command Line option to enter the command line to run. You can click the Edit Post-build button to open a dialog with a larger editor and a list of available macros. Below is an example of a common command line script that can be used (lines wrapped for display purposes). Replace the path to the tool with the path where you installed it on your PC. TheIF statement prevents building the help file in debug builds where it may not be needed.
IF "$(ConfigurationName)"=="Debug" Goto Exit "C:\Program Files\EWSoftware\Sandcastle Help File Builder\ SandcastleBuilderConsole.exe" $(SolutionDir)Doc\TestProject.shfb :ExitIf you want to see verbose output to the console during the build, you can add the /v command line option. All messages are always saved to the log file regardless of whether or not this command line option is used. In a solution with multiple projects that are documented by the same help file builder project, the post-build event should be defined on the last project built by Visual Studio. If the projects are documented individually, you can place a post-build event on each one. Other Build ToolsOther automated build tools also exist. As long as the build tool supports execution of command line based executables with parameters such as SandcastleBuilderConsole.exe, you should be able to integrate it with the build process in a similar fashion.Project Option OverridesIt is also possible to specify project option overrides via the command line and to use a response file to contain a complex list of projects and option overrides to build one or more help files. See the Console Mode Builder topic in the supplied help file for details. Customizing the Build ProcessIn order to provide the ability to customize the main build steps, I opted to place the scripts used to run the tools and the configuration files in the .\Templates folder beneath the installation folder rather than embedding them in the executables. This should allow you to further modify them to add steps or modify the final output without having to recompile the build tools. In each file are a set of substitution tags that will be resolved to one of the project properties and, in some cases, a list of files. See the help file for more details on how this works.The Source CodeThe source code is available for download from CodePlex using the link at the top of the article. The source code download includes a demo project that builds a help file for the tools and includes content from this article and other expanded information as additional content. There are several useful design-time classes and controls in the utilities assembly. I will provide more information on them in a separate article at a later date.ConclusionGiven the architecture of Sandcastle, it is quite flexible and is fairly easy to extend to provide the features that are not there yet. I think the help file builder tools presented here show that quite well. I'm looking forward to the future releases of Sandcastle to see how it progresses.For a list of planned future enhancements and to make suggestions of your own, see the Issue Tracker at the Sandcastle Help File Builder's project website. Revision History
For a full list of all changes in prior versions see the help file supplied with the application.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||