Share Point部署总是一个比较棘手的问题,参考过很多资料你总能找到很多用Feature的方法去部署一个新的功能,而这也恰恰用到了WSS提供的Feature这么一个看点帮助你灵活的将一个功能可以任意部署到某个Share Point服务器上。而对于一个大的项目来讲,我们可能有很多个Feature,或者诸如Master Page,普通页面,事件处理程序等等,这个时候我们就用到了WSS Solution Package,它用于将一个或多个按Feature安装的程序组织成一个MSBuild项目,通过编译成.WSP文件或者CAB文件,最终方便的安装到Share Point服务器。这个项目中你可以方便的组织文件结构,及其安装到服务器的路径,部分配置信息,极大地方便了部署Share Point应用程序。 

在创建WSS Solution Package的过程中,以下几种文件是常常被用来作为配置文件告诉Package部署时的动作。其中有几个是在做普通Feature时很常见的,而又像.DDF文件,.Targets文件和Manefests文件为MSBuild来创建的。(为了准确,保留了部分英语解释。)

·         Manifest.xml(Defines the list of features, site definitions, resource files, web part files, and assemblies to be included in the Solution package)

Manifest.xml文件通常作为Solution的入口点,用来指明在这个Solution中需要去处理的Package—你可以在FeatureManifests节点下指定多个FeatureManifest来执行多个Feature的部署。在英文解释中提到还可以指定别的一些类型的文件,但Assemblies是通常会在这里指定,其他文件最好被声明在各个Feature中。 

·         Feature.xml (Defines the feature and specifies the location of assemblies, files, dependencies, or properties that support the Feature.)

Feature.xml是很常见的配置文件,用来指定所安装的Feature中要包含的DLL,以及其详细配置文件Elements.xml的路径。Feature.xml我们可以认为是单个Feature的入口点,大多数时间之需要指明Elements.xml的路径,而无需将具体操作置入Feature.xml。这样做是为了让我们的配置文件更结构化,功能化。 

·         Elements.xml (Element manifest file containing definitions to the feature's elements.)

Elements.xml文件是最终这个Feature所要做的动作的具体描述。在这里可以应用诸如CustomAction, Module, ModuleGroup, Assemblies, ActivationDependencies, Recievers等扩展标记来告诉Package在部署时要做的动作。 

·         Package.ddf (Package.ddf is a MakeCab diamond directive file used to define the structure and contents of the solution package.)

.ddf文件指定了将来生成的.CAB文件或.WSP文件包含的内容。这里定义了所有需要部署的文件结构信息。需要注意的是,目录结构的变化需要用.SET DESTINATIONDIR=’’ 来显式指定。 

·         Package.Target (Custom the MSBuild project used to create the WSS Solution Package for deployment of the feature. Basically, it changes the defaultTargets to the custom target which calls MakeCab.exe to produce the expected .wsp file.)

因为我们需要创建一个MSBuild项目,但最终生成.WSP文件或者.CAB文件的任务是由MAKECAB.EXE完成的。我们需要给MsBuild项目创建一个任务单,来告诉它去执行MAKECAB并根据设定来创建.WSP文件。因为MSBuild项目的默认构建动作是Build,我们需要变更项目的默认构建动作为指定的DDF,并通过更改Import Project将其要完成的任务交给MsBuild项目去做--这些任务是在Package.Target中完成的。

 1.       对于一个Manifest.xml文件,通常可以作为整个Solution的入口来用,AssembliesFeatureManifests是经常会被用到来制定被部署的DLLsFeatures

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

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

          SolutionId="C44CDF77-456E-4645-A6F7-67AC5790A25C"

          DeploymentServerType="WebFrontEnd"

          ResetWebServer="FALSE">

 

  <Assemblies>

    <Assembly Location="Allan.SharePoint.Package.dll" DeploymentTarget="GlobalAssemblyCache" />

  </Assemblies>

 

 

  <FeatureManifests>

    <FeatureManifest Location=" MasterPages\feature.xml" />

    <!--<FeatureManifest Location="CustomSharePointStyles\feature.xml" />

    <FeatureManifest Location="CustomSharePointWebParts\feature.xml" />

    <FeatureManifest Location="CustomSharePointScripts\feature.xml" /> -->

  </FeatureManifests>

 

</Solution>

 

2.       Feature.xml指定我们需要创建的Feature相关的文件清单。

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

 

<Feature Id="2320b00c-7379-439e-a149-d674765cd7b2" Title="WebParts" Scope="Site" Version="1.0.0.0" Hidden="FALSE" DefaultResourceFile="core" xmlns="http://schemas.microsoft.com/sharepoint/">

 

  <ElementManifests>

    <ElementManifest Location=" MasterPages\feature.xml" />

    <ElementFile Location=" MasterPages\CustomPageLayouts.master" />

    <ElementFile Location=" MasterPages\defaultCustomlayouts.aspx" />

  </ElementManifests>

 

</Feature>

 

3.       创建Elements.xml来定义Feature的操作。

Elements.xml中,Module是个经常被用到标记。MSDN给出的解释是(具体的解释参考MSDNSpecifies files with which to provision SharePoint Web sites within an element manifest. 它和File标记联合使用,其实它本质上是按照ModuleFile指定的路径将文件拷贝到服务器,而这里你可以通过Properties比较来对这些文件添加一些属性。

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

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

  <Module Name="MasterPages"

          Url="_catalogs/masterpage"

          Path="MasterPages"

          RootWebOnly="TRUE">

    <File Url="CustomPageLayouts.master"

          Type="GhostableInLibrary">

 

      <Property Name="ContentType"

                Value="$Resources:cmscore,contenttype_masterpage_name;" />

      <Property Name="PublishingPreviewImage"

                Value="~SiteCollection/_catalogs/masterpage/Preview Images/CustomPageLayouts.jpeg, ~SiteCollection/_catalogs/masterpagePreview Images/CustomPageLayouts.jpeg" />

      <Property Name="Title"

                Value="Allan's custom master page." />

 

</File>

  </Module>

 

  <Module Name=”PreviewImages”

          Url=”_catalogs/masterpage/Preview Images”

          Path=”MasterPages”

          RootWebOnly=”TRUE”>

<File Url=”CustomPageLayouts.jpeg”

          Name=”CustomPageLayouts.jpeg”

          Type=”GhostableInLibrary”/>

  </Module>

 

</Elements>

4.       创建CustomMasterPagePackage.DDF文件来讲Master Page装载进生成的.WSP文件中。这里仅仅指定了将在\Template\FEATURE 目录下创建CustomMasterPageFeature子目录 其实这也是生成的.WSP文件的结构,并将Feature.xml, Element.xml以及MasterPages子目录作为这个Feature的内容。在调用Stsadm.exe –o相关命令操作时,这个Feature将会调用Feature.xml(实际是Elements.xml)的内容来部署相关内容到服务器。

.OPTION Explicit

.Set DiskDirectoryTemplate=CDROM

.Set CompressionType=MSZIP

.Set UniqueFiles=Off

.Set Cabinet=On

;***********************************************

Manifest.xml

 

.Set DestinationDir=CustomMasterPageFeature

Feature.xml

Elements.xml

 

.Set DestinationDir= CustomMasterPageFeature\MasterPages

MasterPages\ CustomPageLayouts.master

MasterPages\ CustomPageLayouts.jpeg

5.       定义CustomMasterPagePackage.targets文件来告诉MSBuild去执行的动作。

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

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"

         DefaultTargets="CustomMasterPagePackage">

 

  <PropertyGroup>

    <MakeCabPath>"C:\Program Files\Microsoft Cabinet SDK\BIN\MAKECAB.EXE"</MakeCabPath>

  </PropertyGroup>

 

  <Target Name=" CustomMasterPagePackage">

    <!-- create Windows SharePoint Services solution package (WSP) file -->

    <Exec Command="$(MakeCabPath) /F CustomMasterPagePackage.ddf /D CabinetNameTemplate=$(MSBuildProjectName).wsp /D DiskDirectory1=$(OutputPath)SpPackage\" />

    <!-- create exact same file as above, but name it *.CAB to make

        it easier to open an view it's contents -->

    <Exec Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"

          Command="$(MakeCabPath) /F CustomMasterPagePackage.ddf /D CabinetNameTemplate=$(MSBuildProjectName).cab /D DiskDirectory1=$(OutputPath)SpPackage\" />

  </Target> 

</Project>

这是整个MSBuild项目的核心它告诉了这个项目编译时(不是Build Action)该做什么动作。我们使用了MAKECAB.EXE(这是一个需要单独安装的工具,用来生成CAB文件。点击这里下载)。默认的路径为:C:\Program Files\Microsoft Cabinet SDK\BIN\MAKECAB.EXE 这个应用程序有两个参数:

·         /F : DDF文件. 指定了在生成cabinet file中的目录结构和资源。

·         CabinetNameTemplate: 实际上就是生成的最终的.wsp文件的名称。

·         /D DiskDirectory1: 所生成的.wsp文件的存放路径。$(OutputPath)\bind\DebugRelease 

6.        更改MSBuild项目的默认构建动作并设置其目标任务单(.Targets.

MSBuild项目的默认构建动作是Build,需要装入的目标任务是对应的语言:

<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

……

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

为了让MSBuild项目来执行我们上边规定的动作,需要重写这两个属性,以强制它来执行MAKECAB.EXE.

<Project ToolsVersion="3.5" DefaultTargets="CustomMasterPagePackage" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

……

<Import Project=”CustomMasterPagePackage.Targets” />

编译整个项目,在Bin\Debug\SpPackage目录下会有以项目名为名称的.CAB文件和.WSP文件。用WinRar或者WinZIp打开.CAB文件,你可以清楚的看到内部构造,这和你在第4步指定的DDF文件所导致的结构是相同的。

接下来用STSADM -o addsolution -filename ***.wsp 命令便可以安装解决方案了。剩余的工作当然是Administrator去激活了。

 

 

 

 

posted on 2008-11-12 15:41  Allan.  阅读(3177)  评论(0编辑  收藏  举报