2009-09-25 63 views
3

我有一個包含許多功能的wsp包。 wsp包中包含的一些功能取決於wsp軟件包中的其他功能。SharePoint功能部署的時機

在我的情況下,2種內容類型是通過功能(內容類型和內容類型B)創建和內容類型B,從內容類型A.繼承

所以,很顯然,包含內容類型的功能(功能A)需要在包含內容類型B(功能B)的功能之前部署。

有沒有一種方法可以在feature B之前部署feature A?理想情況下,這兩個功能將通過onet.xml文件自動激活,功能A只會在之前部署,但我不知道該怎麼做...

我不一定在尋找解決方案這個特殊的問題,但我想知道的是:你如何處理依賴於SharePoint項目中的其他功能的功能?

謝謝!

回答

3

您可以使用功能激活依賴關係...功能。

<Feature Id="01c34560-6561-11dc-8314-0800200c9a66? 
    Title="Nice to know" 
    Description="This is a feature that adds a new sexy CSS" 
    Version="1.0.0.0? 
    Scope="Site" 
    xmlns="http://schemas.microsoft.com/sharepoint/"> 
    <ActivationDependencies> 
    <ActivationDependency FeatureId="F6924D36-2FA8-4f0b-B16D-06B7250180FA"/> 
    </ActivationDependencies> 
    <ElementManifests> 
    <ElementManifest Location="ProvisionedFiles.xml"/> 
    </ElementManifests> 
</Feature> 

look here作爲概述。

+0

感謝一個例子,這是正是我需要的。 – 2009-09-25 18:30:00

4

您還可以創建事件處理程序並按所需順序激活功能。我發現它總是更好地依靠手動代碼而不是使用xml文件來做事情。

看看SPWeb.FeaturesFeatureCollections.Add

下面是我如何編碼這在我的事件處理程序

public void ActivateFeatures(SPFeatureReceiverProperties properties) 
{ 
    logger.Info("Creating content types"); 
    // feature is scoped at Site, so the parent is type SPSite rather than SPWeb.. 
    using (SPSite site = properties.Feature.Parent as SPSite) 
    { 
     SPWeb currentWeb = null; 
     if (site != null) 
     { 
      currentWeb = site.RootWeb; 
     } 
     else 
     { 
      currentWeb = properties.Feature.Parent as SPWeb; 
     } 

     using (currentWeb) 
     { 
      if (currentWeb == null) return; 

      try 
      { 
       currentWeb.Site.Features.Add(new Guid("01A27C0C-2E44-4298-A74F-8F50601A20B0")); // ctCategory 
       currentWeb.Site.Features.Add(new Guid("496DFE3E-A41E-46e8-B627-29775F376017")); // ctChapter 
       currentWeb.Site.Features.Add(new Guid("F2ECBD5A-4766-49bf-A158-62550661E141")); // ctChapterList 
       currentWeb.Site.Features.Add(new Guid("8C91646F-1466-49d7-BB53-B666F164AA96")); // ctComments 
       currentWeb.Site.Features.Add(new Guid("112E1564-FA1C-41fd-853A-F7569C555905")); // ctDocument 
       currentWeb.Site.Features.Add(new Guid("48BD5A07-8DD1-46ef-9F05-9824380BA26E")); // ctExternalReviewer 
       currentWeb.Site.Features.Add(new Guid("20553A8E-8272-400c-816D-6EE8E02F34E9")); // ctStandard 
       currentWeb.Site.Features.Add(new Guid("E84259BD-E4B3-465e-8928-1745F8760F2D")); // ctSuggestion 
       currentWeb.Site.Features.Add(new Guid("0B313654-D296-4bfa-8F21-E4FF33C1DD6C")); // ctTask 
       currentWeb.Site.Features.Add(new Guid("EFDA877B-B686-4954-9F1A-65ADB32B2E50")); // ctDepartment 
       currentWeb.Site.Features.Add(new Guid("4E4B984E-65E2-4601-A216-2C4D08AA97AE")); // ctInnerWork 
       currentWeb.Site.Features.Add(new Guid("4D85D4B9-1909-45cd-81C7-CDBB0874492F")); // ctOtherDocuments 
       logger.Info("Content types added successfully"); 
      } 
      catch (Exception ex) 
      { 
       logger.Error("Could not in activate content types.", ex); 
      } 
     } 
    } 
} 
+0

+1 - 我更喜歡ActivationDependencies的這種方法。也許我是一個控制怪胎,但我喜歡手動處理激活順序:) – dariom 2009-09-25 16:50:37