SharePoint Feature Deployment Dates

I have a wsp package that contains many functions. Some features included in the wsp package depend on other functions that are also in the wsp package.

In my case, 2 content types are created using functions (Content Type A and Content Type B), and Content Type B is inherited from Content Type A.

Therefore, it is obvious that a function containing content type A (function A) must be expanded before a function containing Content Type B (function B).

Is there a way to make the function Expand before function B? Ideally, both functions will be activated automatically through the onet.xml file, and function A will simply be deployed earlier, but I do not know how to do this ...

I'm not necessarily looking for a solution that solves this problem, but I want to know: how do you deal with functions that depend on other functions in a SharePoint project?

Thanks!

+3
source share
3 answers

You can use the function dependency activation function ...

<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>

Take a look here for a review.

+3
source

You can also create an event handler and activate the functions in the order you want. I found it always better to rely on doing things manually in code, rather than using xml files to do something.

Take a look at SPWeb.Features and FeatureCollections.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);
            }
        }
    }
}
+4

.

<ActivationDependencies> 
<ActivationDependency> 

xml elements in the function file. You can read more about it here: http://msdn.microsoft.com/en-us/library/aa543162.aspx

+1
source

Source: https://habr.com/ru/post/1718556/


All Articles