如何一步一步自己做WebPart的CAB安装包

虽然网上提供的方法很多,当大多都要借助第三方工具,其实这件工作很简单,自己动手做也许更方便。

第一步:制作一个WebPart, 假定叫SearchBoxWebPart,强命名它(强命名不是必需的,但推荐使用);
注意事项:AssemblyInfo.cs中记得加[assembly: AllowPartiallyTrustedCallers()]
及AssemblyVersion
第二步:创建一个CAB的Project,添加两个文件,manifest.xml,SearchWebPart.dwp。

manifest.xml内容为:
<?xml version="1.0"?>
<WebPartManifest xmlns="http://schemas.microsoft.com/WebPart/v2/Manifest">
  <Assemblies>
    <Assembly FileName="SearchWebpart.dll">
      <SafeControls>
        <SafeControl Assembly="SearchWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e01f55ae71a39d56" Namespace="SearchWebPart" TypeName="*" Safe="True" />
      </SafeControls>
  <ClassResources>
  </ClassResources>  
    </Assembly>
   
    <Assembly FileName="Microsoft.SharePoint.dll">
      <SafeControls>
        <SafeControl Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint" TypeName="*" Safe="True" />
      </SafeControls>
      <ClassResources>
      </ClassResources>
    </Assembly>

    <Assembly FileName="Microsoft.Office.Server.dll">
      <SafeControls>
        <SafeControl Assembly="Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.Office.Server" TypeName="*" Safe="True" />
      </SafeControls>
      <ClassResources>
      </ClassResources>
    </Assembly>

    <Assembly FileName="Microsoft.Office.Server.Search.dll">
      <SafeControls>
        <SafeControl Assembly="Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.Office.Server.Search" TypeName="*" Safe="True" />
      </SafeControls>
      <ClassResources>
      </ClassResources>
    </Assembly>

    <Assembly FileName="Microsoft.SharePoint.Publishing.dll">
      <SafeControls>
        <SafeControl Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Publishing" TypeName="*" Safe="True" />
      </SafeControls>
      <ClassResources>
      </ClassResources>
    </Assembly>

    <Assembly FileName="Microsoft.SharePoint.Search.dll">
      <SafeControls>
        <SafeControl Assembly="Microsoft.SharePoint.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Search" TypeName="*" Safe="True" />
      </SafeControls>
      <ClassResources>
      </ClassResources>
    </Assembly>

    <Assembly FileName="Microsoft.SharePoint.Security.dll">
      <SafeControls>
        <SafeControl Assembly="Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Security" TypeName="*" Safe="True" />
      </SafeControls>
      <ClassResources>
      </ClassResources>
    </Assembly>
 
  </Assemblies>
 <DwpFiles>
  <DwpFile FileName="SearchWebpart.dwp"/>
 </DwpFiles>

</WebPartManifest>

Assembly指定的dll会被安装到SharePoint的bin目录中。


SearchWebPart.dwp的内容为:
<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" >
 <Title>SearchWebpart</Title>
 <Description>Custom search web part</Description>
 <Assembly>SearchWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e01f55ae71a39d56</Assembly>
 <TypeName>SearchWebPart.SearchBoxWebPart</TypeName>
</WebPart>
它将指定要安装的WebPart.

第三步:将所有所需的dll加到CAB Project中。

第四步:使用stsadm  命令安装。
install: stsadm -o addwppack -filename C:\SearchWebpartSetup.CAB  –url [URL if you want to deploy to a specific site]

uninstall: stsadm -o deletewppack -name SearchWebpartSetup.CAB

你可能感兴趣的:(part)