Expand Minimize

SMA265201: Avoid deployment of ContentTypes via Feature Framework

Deploying ContentTypes through the Feature Framework creates dependencies on the provisioning XML files. Break this dependency to help future migrations, and updates by using the Remote Provisioning techniques from Microsoft.

CheckId SMA265201
TypeName ContentTypeRecommendations
Severity CriticalWarning
Type ContentType

Full Trust Approach App Approach
Content Types

A content type, is a shared definition of a list. It describes Fields and Views, which can be reused where they are deployed.

Paradigm Shift - Deployment through Code

An alternate method is the creation of Content Types through code. This method takes the structure of a List, and creates the Content Type programmatically. While also popular in Full-Trust solutions, it is the preferred method through the App Model, doing the same provisioning process remotely.

Impact of Full Trust Approach Benefit of App Approach
Dependency on Deployed Files

When you create a an element in SharePoint from a Declarative file, the content you have created is then dependent on the xml files they are described in. When these need to be retracted, due to an update, a change in the system, or part of a disaster recovery plan, this link is broken. This will ultimately cause issues in the long run.

Cloud Application Model

The Cloud Application Model or CAM, is designed to create content through code, therefore not creating any dependency links.

<?xml version="1.0" encoding="utf-8" ?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ContentType ID="0x0101009189AB5D3D2647B580F011DA2F356FB2"
    Name="Contoso Document"
    Group="Contoso Content Types"
    Version="0">
    <FieldRefs>
    ...
    </FieldRefs>
  </ContentType>
</Elements>
ContentTypeCollection contentTypes = web.ContentTypes;
cc.Load(contentTypes);
cc.ExecuteQuery();

foreach (var item in contentTypes)
{
  if (item.StringId == "0x0101009189AB5D3D2647B580F011DA2F356FB2")
  return;
}

// Create a Content Type Information object
ContentTypeCreationInformation newCt = new ContentTypeCreationInformation();
newCt.Name = "Contoso Document";
newCt.Id = "0x0101009189AB5D3D2647B580F011DA2F356FB2";
newCt.Group = "Contoso Content Types";
ContentType myContentType = contentTypes.Add(newCt);
cc.ExecuteQuery();

Efforts and Benefits

Migration Impact High
Re-Design Effort Medium
Re-Development Effort High
Long Term Benefit Critical

Effort Drivers

  • No hard links between the provisioning procedure, and the content
  • Easily Migratable, and Future Proofed

To suppress this violation in XML SharePoint code add the following comment right before the XML tag which causes the rule violation. Learn more about SuppressMessage here.

<!-- "SuppressMessage":{"rule":"SMA265201:ContentTypeRecommendations","justification":"Provide reason for suppression here"} -->
Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of RENCORE AB. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.