SPC052101: Do not activate or deactivate Features via API

Do not activate or deactivate Features in code via API. Consider using Powershell or Feature Stapling.

TypeName: DoNotActivateFeaturesViaAPI
CheckId: SPC052101
Severity: CriticalWarning
Type: AssemblyFileReference
Resolution

Remove calls to SPFeatureCollection.Add() and SPFeatureCollection.Remove() to activate or deactivate Features. Use PowerShell or Feature Stapling instead.

Bad Practice:

// code activates a feature in current web
SPWeb currentWeb = SPContext.Current.Web;
currentWeb.Features.Add(new Guid("{75bb640f-a94e-4893-819c-6ef5f14e1984}"));

Links

comments powered by Disqus