Jarody's profile三省吾身PhotosBlogListsMore Tools Help

Blog


    January 22

    在VS2005中创建项目模板来提高开发效率

    通常情况下,我们会在一段时间内,使用同一种开发工具开发结构相近的项目,比如在VS2005中开发Web应用程序,数据访问使用iBATIS.NET。对于Web项目来说,它往往包含了js、css、image等文件夹和相应文件,还有经过配置的Global.asax、web.config文件,此外还有通用的用户管理、日志等内容;使用iBATIS时,则需要包含dao.config、sqlMap.config、providers.config等文件。我们可以在项目开始时将这些文件拷贝过去。这也许不是什么大问题,但毕竟还是不方便。

    项目模板和项模板可给我们带来方便,为我们省却上面的烦恼。

    结构

    首先来看看VS2005中的模板结构。VS2005默认附带了一些项目模板,比如Windows 应用程序,类库,Web Site以及Web Service等。在新建一个Web Site项目时,会出现下面的窗体:

    VS2005会选择下面目录中的模本:

    C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\Web\CSharp\1033

    当然这个路径取决于VS2005的安装路径。

    看看这个文件夹下的文件,会发现每个项目都对应于一个zip文件。zip文件里包含创建项目所需的文件,还包含了一个扩展名为vstemplate的文件,该文件包含了创建项目所需的信息,并以XML的格式存储了项目模板的元数据(Meta data)。

    简单来说,创建模板需要创建vstemplate文件和zip文件包。但是,我们在何处存放zip文件呢?VS2005给了我们很大的自由,我们甚至可以存放在网络驱动器中,这对团队开发会大有裨益。那么如何配置呢?

    1、在VS2005中,打开Tools->Options

    2、展开Projects & Solutions

    3、点击General

    4、修改相应的项目模板或项模板位置,可以是网络启动器

    经过上述配置后,团队中的开发人员可以共享一组项目模板。

    创建项目模板

    创建模板的过程相当简单。

    1、创建一个预定义的模板

    2、进行修改,比如添加页面、类等

    3、保存项目

    4、点击File->Export Template

    5、跟随向导完成创建。

    为演示该过程,我创建了一个名为templatearticle的网站。文件夹结构看起来如下:

    然后点击File->Export Templates,导出模板的向导窗体出现:

    此处可以选择模板类型,模板的源项目,模板项目所用的语言。

    点击Next。

    出现Select Template Options窗体:

    设置模板名称和描述信息。可以选中“自动导入到Visual Studio”。

    点击Finish完成。

    创建项模板过程类似,只需在第一步时将模板类型选择为Item Template。

    使用项目/项模板

    通过上述步骤,我们已经成功创建了项目/项模板。下面来看一下如何使用它们。

    1、通过项目模板创建项目

    • 点击File->New->Web Site.
    • New Web Site会出现

    • 在My Templates中,可以注意到有个名为Template Article的模板。
    • 在输入站点名称后,项目就得以创建。

    从模板创建项

    右击项目文件夹,选择Add New Item

    Add New Item Window出现

    可以看到Registration Class项模板。

    输入名称,项得以创建。

    至此,模板创建和使用的简单介绍就完成了。不过它的详细用法就要你去研究了 :)

    参考:

    Speed Up with Project Templates Using Visual Studio 2005

    本文来自于博客园 作者:Anders Cui

     

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://silentjarody.spaces.live.com/blog/cns!2366A19CCA30E048!163.trak
    Weblogs that reference this entry
    • None