现在的位置: 首页 > 综合 > 正文

在Vs.net中集成 NDoc生成的 Html Help 2帮助文档

2011年06月30日 ⁄ 综合 ⁄ 共 2748字 ⁄ 字号 评论关闭


注:
NDoc是一个Open SourceFor .Net 文档自动生成软件。它可以通过 .NetXML的注释标签来生成非常漂亮的MSDN风格的类库文档。(相对于VS.Net自己带的Comment Web Page生成工具好多了)

 

《在Vs.net中集成 NDoc生成的 Html Help 2帮助文档》

 

By: Fons Sonnemans

编译: linkcd

 

代码下载:NDocSample.zip

 

简介:

NDoc 可以根据C#编译器编译出的.Net组件(Assemblies)和XML文档来生成类库的文档。 NDoc可以由附加的文档器(documenter)来生成不同格式的文档,包括MSDN风格的HTML Help File.chm), VS.net帮助文档(Html Help2),以及MSDN风格的Web在线文档。

(译注:产生的格式要比VS.net自己由xml tag生成的在线文档好看的多)

 

本篇文章分4个步骤来介绍如何由NDoc生成类库文档并集成到VS.net中。

1.        使用XML文档标记来注释您所编写的类库

2.        NDoc来创建HTML Help 2文档

3.        使用H2Reg来注册帮助文档

4.        把帮助文档集成到VSCC

 

第一步:使用XML文档标记来注释您所编写的类库

我编写了一个简单的库,包括了2个类: Employee EmployeeCollection。这些类都采用了XML风格的注释标签(///)。 这个组件被命名为ReflectionIT.NDocSample

 

using System;

namespace ReflectionIT.NDocSample
{
    
/// <summary>
    /// Employee class used to demonstrate NDoc and Visual Studio.NET integration.
    /// </summary>
    /// <example>
    /// Some sample:
    /// <code>
    /// Employee emp = new Employee("Jim", 4000);
    /// emp.RaiseSalary();
    /// Console.WriteLine(emp.GetYearSalary);</code>
    /// </example>
    public class Employee
    
{
        
private string _name;
        
private int _salary;

        /// <summary>
        /// Initializes a new instance of the Employee class with a name and salary.
        /// </summary>
        /// <param name="name">The name of the employee</param>
        /// <param name="salary">The salary of the employee</param>
        public Employee(string name, int salary)
        
{
            
this.Name = name;
            
this.Salary = salary;
        
}

        /// <summary>
        /// Gets or sets the name of the employee.
        /// </summary>
        public string Name {
            
get { return this._name; }
            
set { this._name = value; }
        
}

        /// <summary>
        /// Gets or sets the salary of the employee.
        /// </summary>
        public int Salary {
            
get { return this._salary; }
            
set { this._salary = value; }
        
}

        /// <summary>
        /// Returns the year salary for the employee using 12 months
        /// </summary>
        /// <returns>The year salary</returns>
        public virtual int GetYearSalary() {
            
return Salary * 12;
        
}

        /// <summary>
        /// Raise the salary with 10%
        /// </summary>
        public virtual void RaiseSalary() {
            Salary
+= Salary * 10 / 100;
        
}
    
}
}

 

这个组件被命名为ReflectionIT.NDocSample 同时,我把该组件生成的xml注释文件命名为ReflectionIT.NDocSample.XML 。请确认xml文件的名字和该组件的名字一致,否则IntelliSense将无法正确的工作。最后不要忘记编译该组件:编译之后就会生成这个xml文件。

 

第二步:使用NDoc创建 HTML Help 2 文档

NDoc中同时包括GUI前台程序(NDocGUI.Exe)和 控制台文件(NDocConsole.exe)。我使用 NDocGUI来创建一个NDoc项目给我的NDocSample类库服务。您也可以通过“New From Visual Studio Solutioin…”菜单项来进行。

 

现在,你要将文档类型(Documentation Type)设置为“HtmlHelp2”。此外,还可以根据项目不同的情况来修改一些额外的属性,比如CopyrightHref, CopyrightText, HtmlHelpName Title等等。

(译注1CopyrightHref中请使用 http://www.ncsi.com.cn这样的格式,而不要仅仅写成www.ncsi.com.cn
(译注2NDoc同时还可以支持生成其他类型的文档。如果您不需要把文档集成到VS.net里面,只是想生成一个MSDN风格的在线Web页或CHM

抱歉!评论已关闭.