sharepointdeploymentcontenttype

Best practice for deploying multiple content types with dependencies in SharePoint


I'm developing a solution with approx. 15 custom content types. Therefore I created in Visual Studio a SharePoint Project and added content types defined in XML Markup. As some of these content types use references between each other (Lookup-Columns), I added List Definitions and List Instances as well. As lookups can be declared in XML since SharePoint 2010 - everything's fine.

Now my feature contains all the content types, the list definitions and the list instances.

But the problem is: Sometimes the deployment succeeds and sometimes it fails. I suppose this may occur because the elements within the features have no activation order. Now I could change my project and create a feature for every content type and define acitvation dependencies to define an activation order. But this would lead to at least 20 features and in my opinion this can't be the supposed solution to handle this correctly.

What's the correct way to deploy content types with lookups to other content types within the same solution?

There's one restriction: everything has to be sandboxed because I want to deploy in SharePoint Online.


Solution

  • I believe I had the same problem as you - I defined two content types; A and B, B relied on A. and both were in the single feature. However when it came time to deploy I received an error:

    Error occurred in deployment step 'Activate Features': The parent content type specified by content type identifier 0x010029043F0D68EC4DF1BC85141AFF451661 does not exist.

    I looked in the Manifest.xml file that Visual Studio generates inside the wsp/cab file and noticed the two content type Elements.xml files were defined the wrong way around:

    1. B/Elements.xml
    2. A/Elements.xml

    A work around to this is to simply force the order of certain Elements.xml file in the feature (i.e. put the 'root' content type files first).

    Open the feature, go to Manifest, open Edit Options and enter the file you need to be specified first in the list of Elements.xml files.

    <ElementManifests>
      <ElementManifest Location="A\Elements.xml" />
    </ElementManifests>
    

    This emits the following XML into the manifest file:

    <ElementManifests>
      <ElementManifest Location="A\Elements.xml" />
      <ElementManifest Location="B\Elements.xml" />
    </ElementManifests>