使用Sandcastle生成类库说明文档示例(图文)




本文用一个实例来说明如何生成一个类库项目的帮助文档以方便在类库以后的使用中方法查阅(比如我们平时自己写个通用类库,可过一段时间再使用的话可能要去看原码),主要是方便自己以后参考,如果对您也有用那就更好了。

一、使用Visual Studio 2008新建一个类型项目BookLib(为了方便说明,这里只是一个简单的类),见下图:

使用Sandcastle生成类库说明文档示例(图文) - 平凡人生 - 股票 NBA 网络技术 SEO网站优化

二、在项目中添加Book类和BookType类,目录如下图:

使用Sandcastle生成类库说明文档示例(图文) - 平凡人生 - 股票 NBA 网络技术 SEO网站优化

为了方便,在每个类里添加一些方法和属性,如下:

BookType.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BookLib
{
    /// <summary>
    /// 图书类型
    /// </summary>
    public class BookType
    {
        #region 属性
        /// <summary>
        /// 图书类型名称
        /// </summary>
        public string TypeName { get; set; }

        /// <summary>
        /// 图书类型编号
        /// </summary>
        public int TypeId { get; set; }
        #endregion

        #region 私有成员方法
        /// <summary>
        /// 查询指定的分类名称是否存在
        /// </summary>
        /// <param name="TypeName">分类名称</param>
        /// <returns>分类名称是否已存在</returns>
        private bool BookTypeExists(string TypeName)
        {
            //这里为了方便没有写具体的功能
            return false;
        }
        #endregion

        #region 公共成员方法
        /// <summary>
        /// 添加图书分类
        /// </summary>
        /// <param name="TypeName">分类名称</param>
        /// <returns>添加是否成功</returns>
        public bool AddBookType(string TypeName)
        {
            return !BookTypeExists(TypeName);
        }
        #endregion
    }
}

Book.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BookLib
{
    public class Book
    {
        #region 属性
        /// <summary>
        /// 所属分类编号
        /// </summary>
        public int TypeId { get; set; }

        /// <summary>
        /// 图书名称
        /// </summary>
        public string BookName { get; set; }

        /// <summary>
        /// 图书价格
        /// </summary>
        public decimal BookPrice { get; set; }
        #endregion

        #region 成员方法
        /// <summary>
        /// 添加图书
        /// </summary>
        /// <param name="bookName">图书名称</param>
        /// <param name="bookPrice">图书价格</param>
        /// <param name="typeId">图书分类编号</param>
        /// <returns>添加是否成功</returns>
        public bool AddBook(string bookName, decimal bookPrice, int typeId)
        {
            return true;
        }

        /// <summary>
        /// 删除指定的图书
        /// </summary>
        /// <param name="bookName">要删除的图书名称</param>
        /// <returns>是否删除成功</returns>
        public bool DeleteBook(string bookName)
        {
            return true;
        }
        #endregion
    }
}

三、生成项目,应注意的是要将项目属性中【生成】选项卡中的XML文档文件选项设置于选中状态,如下图:

使用Sandcastle生成类库说明文档示例(图文) - 平凡人生 - 股票 NBA 网络技术 SEO网站优化

项目生成后,在bin\degug目录中生成的文件有与DLL文件同名和一个XML文件,如下图:

使用Sandcastle生成类库说明文档示例(图文) - 平凡人生 - 股票 NBA 网络技术 SEO网站优化

四、启动Sandcastle Help File Builder GUI,新建一个项目BookLibHelp,如下图:

使用Sandcastle生成类库说明文档示例(图文) - 平凡人生 - 股票 NBA 网络技术 SEO网站优化

五、选择Add Documentation Source将刚刚创建的类库项目添加到项目中,见下图:

使用Sandcastle生成类库说明文档示例(图文) - 平凡人生 - 股票 NBA 网络技术 SEO网站优化

在弹出的对话框中选择BookLib类库项目,如下图:

使用Sandcastle生成类库说明文档示例(图文) - 平凡人生 - 股票 NBA 网络技术 SEO网站优化

然后在Sandcastle Help File Builder的项目浏览器中我们会看到显示了我们刚刚选择的类库项目,如下图:

使用Sandcastle生成类库说明文档示例(图文) - 平凡人生 - 股票 NBA 网络技术 SEO网站优化

六、设置Sandcastle Help File Builder的项目属性,如下图:

使用Sandcastle生成类库说明文档示例(图文) - 平凡人生 - 股票 NBA 网络技术 SEO网站优化

说明:选项很多,只说一下我们要用到的就可以了,别的如果有兴趣可以Google或Baidu
1、类库项目使用的Framework的版本
2、生成的帮助文件类型(之前说过2.0的帮助文件没有特殊的浏览器是没有办法浏览的,所以我们生成1.x的类型)
3、Sandcastle的安装路径(不知道Sandcastle是什么?请Google或Baidu一下)

七、编译项目,等待一段时间后显示编译完成在Sandcastle项目目录中的Help目录下就生成了我们类库的帮助文档,如下图:

使用Sandcastle生成类库说明文档示例(图文) - 平凡人生 - 股票 NBA 网络技术 SEO网站优化

OK,我们看一下帮助文档的内容吧,下图:

使用Sandcastle生成类库说明文档示例(图文) - 平凡人生 - 股票 NBA 网络技术 SEO网站优化

和MSDN中的一样,用起来很方便。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
https://marketplace.visualstudio.com/items?itemName=DonAirey.ResourceGenerator&ssr=false#qna This package contains a custom tool that can be used to replace the PublicResXFileCodeGenerator that Microsoft uses by default to generate resources. The biggest problem with the Microsoft default code generator is that the generated constructor is protected, which means that it can’t be used to construct strongly-typed resources in Visual Studio in Portable Class Libraries (PCL). Simply replace the PublicResXFileCodeGenerator custom tool on all the resources with ResourceGenerator and a portable version of the resources will be generated. To create portable resources, start with a Portable Class Library project. Create a directory for your resources (e.g. Strings, this step is optional). The right click on the project, select “Add…” and select Resources File from the options. Name the file whatever you want (e.g. Resources, Errors, etc.) and hit Add. Select the .RESX file from the Solution Explorer window and hit F4 to get to the properties. In the Custom Tools property, remove ResXFileCodeGenerator or PublicResXFileCodeGenerator and type in ResourceGenerator. Now your solution can use these strings from code or XAML, in WPF, Windows 8 or UWP projects. To add localization, create a copy of the resource file and add extensions for the cultures you want to support, such as en-GB, fr-FR or any other combination. After adding the resource file, updating the extension, and translating the text (I’m a big fan of Google Translate for this part), you will need to remove the ‘Custom Tool’ property and make sure that each of the culture files has an Embedded Resource as a Build Action. The directory should look like this:

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值