【问题标题】:Timing in SharePoint features deploymentSharePoint 功能部署中的时间安排
【发布时间】:2009-09-25 15:19:09
【问题描述】:

我有一个包含许多功能的 wsp 包。 wsp 包中包含的一些功能依赖于 wsp 包中的其他功能。

在我的例子中,两种内容类型是通过功能创建的(内容类型 A 和内容类型 B),内容类型 B 继承自内容类型 A。

显然,包含内容类型 A(功能 A)的功能需要在包含内容类型 B(功能 B)的功能之前部署。

有没有办法让功能 A 在功能 B 之前部署?理想情况下,这两个功能都将通过 onet.xml 文件自动激活,而功能 A 将在之前部署,但我不知道该怎么做...

我不一定要寻找解决此特定问题的解决方案,但我想知道的是:您如何处理依赖于 SharePoint 项目中其他功能的功能?

谢谢!

【问题讨论】:

    标签: sharepoint wss-3.0


    【解决方案1】:

    您还可以创建一个事件处理程序并按照您想要的顺序激活这些功能。我发现依靠在代码中手动执行操作而不是使用 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);
                }
            }
        }
    }
    

    【讨论】:

    • +1 - 我更喜欢这种方法而不是 ActivationDependencies。也许我是个控制狂,但我喜欢手动处理激活顺序:)
    【解决方案2】:

    您可以使用功能激活依赖项...功能。

    <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 了解概览。

    【讨论】:

    • 谢谢,这正是我所需要的。
    【解决方案3】:

    您可以使用激活依赖项将功能相互关联。你用

    <ActivationDependencies> 
    <ActivationDependency> 
    

    特征文件中的xml元素。你可以在这里读更多关于它的内容: http://msdn.microsoft.com/en-us/library/aa543162.aspx

    【讨论】:

      猜你喜欢
      • 2019-06-26
      • 2011-04-12
      • 2012-05-25
      • 1970-01-01
      • 2013-09-14
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      • 2010-10-04
      相关资源
      最近更新 更多