Sharepoint Solution 一:创建一个简单的Sharepoint Solution

sharepoint开发中,自定义的feature或是webpart要发布到Production Server上。很多时候是开发人员先在test server上开发并测试,然后发布到production server,因此部署的时候是比较麻烦的,比较方便的方法是将开发的featurewebpart打包成一个sharepoint solution(.wsp文件),然后使用stsadm命令发布到指定的server上。下面先来介绍如何将一个feature打包成solution并发布。

Step1. 先来创建一个文件夹结构吧。如下所示

MyTestSolution                     (Solution文件夹)

        Bin                                            (放置生成的Solution文件)

        Source                                         (Feature以及其他需要包含的文件)

               SuhuaTestList              (自定义的Feature

                      ListTemplates

                      Messages

       其中Feature的组织结构是仿照Sharepoint中的Feature结构,可以到

C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES/ 目录下查看DiscussionList

      Step2. 创建Feature

      我们就基于Sharepoint discussions list来创建一个Feature。在SuhuaTestList文件夹下创建一个feature.xml文件,如下所示:

      <?xml  version="1.0" encoding="utf-8"?>

<Feature Id="C6C9FBCB-330F-483b-9367-7A7BD9AAF34B"

    Title="Suhua Test Feature"

    Description="This is my feature containing a list"

    Version="1.0.0.0"

    Hidden="FALSE"

    Scope="Web"

    DefaultResourceFile="core"

    xmlns="http://schemas.microsoft.com/sharepoint/">

    <ElementManifests>

      <ElementManifest Location="ListTemplates/MyListManifest.xml" />

      <ElementFile Location="Messages/schema.xml"/>

    </ElementManifests>

</Feature>

其中的Feature Id可以使用Guidgen.exe创建。

C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES/DiscussionsList/Discuss中将

 schema.xml拷贝到Messages文件夹下。

ListTemplates文件夹下创建MyListManifest.xml,如下所示:

<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <ListTemplate

    Name="Messages"

    Type="108"

    BaseType="0"

    OnQuickLaunch="FALSE"

    FolderCreation="FALSE"

    SecurityBits="12"

    Sequence="999"

    DisplayName="Suhua test List"

    Description="This is my custom list based on the discussions list"

    Image="/_layouts/images/itdisc.gif"/>

</Elements>

这里要注意的是,ListTemplate标签下的Name属性必须跟schema.xml所在的文件夹(Messages)的名字一样。

Step3. 构建Solution Package(.wsp文件)

首先要在Source文件夹下创建一个manifest.xml文件,这个文件定义了要处理的features, site definitions, resource files, Web Part files, and assemblies。如果一个文件包含在solution中但是没有在manifest.xml文件中列出来,这个文件就不会被处理。

<?xml version="1.0" encoding="utf-8"?>

<Solution xmlns="http://schemas.microsoft.com/sharepoint/"

          SolutionId="09BC4315-5234-4070-BBFA-B437B737370A" >

  <FeatureManifests>

    <FeatureManifest Location="SuhuaTestList/Feature.xml"/>

  </FeatureManifests>  

</Solution>

      接下来就要生成wsp文件了,.wsp文件实际上是一个.cab文件,区别就是后缀名不一样。可以使用makecab.exe创建,这需要一个.ddf文件。在Source文件夹下创建一个文件wsp.ddf,内容如下所示:

.OPTION Explicit

.Set DiskDirectory1="../bin"

.Set CabinetNameTemplate="SuhuaListSolution.wsp"

manifest.xml

.Set DestinationDir="SuhuaTestList/ListTemplates"

SuhuaTestList/ListTemplates/MyListManifest.xml

.Set DestinationDir="SuhuaTestList/Messages"

SuhuaTestList/Messages/schema.xml

.Set DestinationDir="SuhuaTestList"

SuhuaTestList/Feature.xml

      在这个文件中,我们将生成的wsp文件放置到../bin目录下,名字为SuhuaListSolution.wsp。接下来告诉makecab有四个文件,同时在部署时要创建三个文件夹(DestinationDir)。

      现在一切都准备好了,使用makecab.exe就可以创建solution了,也就是wsp文件。可以运行cmd,然后执行makecab。这里介绍个简单的可以重复使用的方法,就是建立一个build.cmd文件,然后以后也可以直接拷贝到其他的需要的地方双击执行就行:

@setlocal

@pushd.

 @cd %~dp0

 makecab /f wsp.ddf

@popd

@endlocal

      现在去bin目录下看看,是不是生成了一个wsp文件。这个文件就是我们需要的sharepoint solution 文件了。

      Step4. 部署solution

      生成的wsp文件,如何部署到production server中呢?这就要用到Stsadm命令工具。此它位于%PROGRAMFILES%/common files/microsoft shared/web server extensions/12/bin目录下利用此命令行工具,可访问整套 Windows SharePoint Services 3.0 操作。可通过命令行或通过批处理文件或脚本来使用 Stsadm。必须在服务器本地运行 Stsadm

         运行cmd,到stsadm所在的目录执行以下命令:

stsadm.exe -o addsolution -filename MyListSolution.wsp
stsadm.exe -o deploysolution -name MyListSolution.wsp -local

       上面第一条命令是将solution添加到sharepoint中,第二条命令是部署到solution中。

       如果想要移除这个solution可以执行下面的命令

stsadm.exe -o retractsolution -name MyListSolution.wsp –local
stsadm.exe -o deletesolution -name MyListSolution.wsp

       除此之外,也可以使用Sharepoint 3.0 Central Administration来部署solution。方法是启动Administrative Tools中的Sharepoint 3.0 Central Administration,然后选择Operations中的Solution Management

       Step5. 使用Features

       部署完之后,就可以使用自定义的discussion list啦,但必须先激活这个feature。打开sharepoint,在Site Setting中选择Site features,然后激活前面创建的feature。接着就可以在Create页面中看到自定义的List了。

(参考:http://geekswithblogs.net/evgenyblog/archive/2008/01/27/118966.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值