Naming |
Checks files and artifacts for violations against naming conventions.
Intention
Beside the naming conventions of the .NET Framework Design Guidelines (which applies for code in assemblies) SharePoint code needs additionally naming conventions to cover code in XML files (like Features, ContentTypes), naming of deployed files and naming of IDs in XML code. The following sections describe the additional SharePoint naming conventions and provide an index of naming rules of SPCAF.
- Naming of Solution Files
- Naming of Features
- Naming of Assemblies
- Naming of Files and Folders
- Naming of IDs
- Index of Naming Rules
Naming of Solution Files
Typically a SharePoint application consists of multiple WSP solutions. Although it is a best practices to reduce the number of WSP packages it is often necessary, to split the code of an application into separate packages. Furthermore in most cases Solution packages from different vendors or different applications are deployed to the same SharePoint farm. Thus, it is necessary to use a strict naming convention for Solution packages.
Use namespace for solution filesTo achieve unique naming of Solution packages in the Solution Gallery a namespace should be used for the package file. This name should follow the existing Namespace Naming Guidelines of .NET. Adjusting these guidelines to SharePoint the name of the solution package should start with the company name, followed by name of the application or project:
MyCompany.CorporateIntranet.CoreComponents.wsp
.
Use version number
Sometimes it is necessary to deploy the same application in different versions into SharePoint. In this case it should be recongnizable for the administrator to see the dependencies between both applications by a version number. To avoid long version numbers in the solution name only the major version should be added to the name. The version number should be the last part of the solution filename:
MyCompany.CorporateIntranet.CoreComponents.V2.wsp
.
Reflect package containment in name
Additional reasons for multiple SharePoint solutions packages are:
- Separation depending on deployment scope of farm solutions (deployment globally or per WebApplication)
- Separation of Assemblies from SharePoint files, e.g. to reduce IISReset during deployment
- Separation of global Resources from the rest of the code to support LanguagePacks for an application
- Separation of independent components, like 'Webparts', 'Services', 'WebServices'
- Separation depending on deployment model (farm solutions vs. sandboxed solutions)
To reflect the different types of Solutions the following naming conventions are used to make the differences visible. This may help SharePoint administrators to see which type of solution is deployed into the farm or to a sitecollection in the 'Solution Gallery'.
Purpose of solution | Naming Rule | Samples |
---|---|---|
Solutions with different components | Company.Intranet.WebParts.wsp Company.Intranet.ContentTypes.wsp Company.Intranet.Branding.wsp |
|
Solution with strong dependency to other Solution | Company.Intranet.WebParts.Common.wsp Company.Intranet.WebParts.Resources.wsp |
|
Solution with a new version | Company.Intranet.WebParts.V1.wsp Company.Intranet.WebParts.V2.wsp |
|
Solution for global Resources | Company.Intranet.Resources.wsp | |
Sandboxed Solution | [Company].[Project].[ComponentName].Sandboxed.wsp | Company.Intranet.WebParts.Sandboxed.wsp Company.Intranet.WebParts.Sandboxed.V2.wsp |
Naming of Features
Features are deployed to folder \TEMPLATE\FEATURES and therefore the folder name must be unique. The name of the feature folder should start with the name of solution which deploys the feature, an underscore and the name of the feature (which must be unique within the solution). .
\TEMPLATE\LAYOUTS\MyCompany.CorporateIntranet.CoreComponents.V2_ContentTypesFeature
.
Naming of Assemblies
In general assemblies should follow the .NET Framework Design Guidelines.
In SharePoint the name of assemblies should contain the name of the Solution package which deploys the assembly. For instance, if assemblies are deployed in Solution file MyCompany.CorporateIntranet.CoreComponents.wsp
, the assemblies in this package should start with MyCompany.CorporateIntranet.CoreComponents
, for instance MyCompany.CorporateIntranet.CoreComponents.Services.dll
. Especially if assemblies are deployed to GAC this approach helps to see the relation between the assembly and the solution package which deployed the assembly.
Naming of Files and Folders in Package
The most critical part is the naming of deployed files and folders. A wrongly named file can make SharePoint inaccessible, e.g. if a SharePoint system file is replaced accidentally. Furthermore if SharePoint code from different vendors or different applications is deployed it is important to use unique names for folder and files.
General rule: Use name of Solution package in files and foldersAll files and folders are deployed by a WSP solution package. To ensure uniqueness of the names and to make the relation between the package and the files visible the name of the solution package should be part of the file or folder.
To avoid characters '.' in the name of folders and files this character should be replaced by underscore.
\TEMPLATE\LAYOUTS\MyCompany.CorporateIntranet.CoreComponents.V2\filename.xml
.
Use subfolders if possible
If possible files should not be deployed directly into a SharePoint system folder. A subfolder should be created instead. The name of the folder should be unique and therefore should contain the namespace of the solution package.
Use unique filename if subfolder is not possibleSeveral files cannot be deployed into a custom subfolder and must be deployed directly into a SharePoint system folder. Samples are:
- Control templates (must be deployed file to \TEMPLATES\CONTROLTEMPLATES)
- FieldTypes (must be deployed as .xml file to \TEMPLATES/XML)
- Custom SiteDefinitions (must be deployed as .xml file to \TEMPLATE\1033\XML)
- Global Resources (must be deployed as .resx file to \Resources)
Pattern | Naming Rule | Samples |
---|---|---|
Files which can be placed into subfolder | Create folder with namespace and put all files into the folder | TEMPLATES/LAYOUTS/Company_Intranet_WebParts/Page.aspx TEMPLATES/IMAGES/Company_Intranet_WebParts/icon.gif |
Files which cannot be placed into subfolder | Add namespace into the name of the file | \TEMPLATE\XML\fldtypes_Company_Intranet_WebParts_Fields.xml \TEMPLATE\CONTROLTEMPLATES\Company_Intranet_WebParts_Control1.ascx |
Feature Folder | Add namespace to feature folder | \TEMPLATE\FEATURES\Company_Intranet_WebParts_SiteFeature/feature.xml |
Naming of IDs
Several components contain attributes (like IDs) which must be unique across the farm. Often a GUID can be used for these attributes (e.g. for FeatureID). Sometimes it is better to use a readable name for IDs instead of using a GUID. For these IDs the namespace of the solution package should be part of the attribute.
<CustomAction
Id="Company.Intranet.CoreAction.MyAction"
Location="CommandUI.Ribbon"
RegistrationId="101"
RegistrationType="List"
Title="My Action">
...
</CustomAction>
</Elements>
Type of Element | Unique Attribute | Samples |
---|---|---|
CustomActionGroup | Id | Company.Intranet.CustomActions.MainGroup |
CustomAction | Id | Company.Intranet.CustomActions.EditFile |
Control Template | Id | Company.Intranet.CustomActions.EditFile |
Field Type | TypeName | Company.Intranet.CustomActions.MyFieldType |
Index
Rule | Description | Type | Severity |
---|---|---|---|
SPC080101: Define Solution name as valid namespace | To make it easier to identify the correct wsp solution in the solution store the name of the solution should be a valid namespace (e.g. 'Company.Project.Components.wsp'). | Solution | Warning |
SPC080102: Files or Folders should contain the name of the parent solution | Files or their folders should be named after the solution. This helps do make the file location unique to prevent overwriting of existing files and it is easier to see which WSP solution deployed the file. The rule is case sensitive. | Solution | Warning |
SPC080103: Solution name should start with company name | The solution name should start with company name to follow the rule 'CompanyName.ApplicationName.ComponentName.wsp'. | Solution | Warning |
SPC080801: WebTemplate file in site definitions should start with 'WEBTEMP' | The name of the WebTemplate files should start with 'WEBTEMP'. | WebTempFile | Warning |
SPC082101: Feature name should start with solution name | A feature name should be prefixed with the name of the parent solution. This helps to make the feature name unique and it is easier to see which WSP solution deployed the feature. The rule is case sensitive. | Feature | Warning |
SPC082201: Declare FieldType in File 'fldtypes_[namespace].xml' | The XML file which contains FieldTypes should follow the pattern 'fldtypes_[Namespace].xml'. [Namespace] represents the name of the WSP solution with replaced '.' with underscore. Reason: All FieldTypes are deployed to folder /SharePointRoot/Templates/XML and therefore must be stored in a file with a unique filename to avoid overriding existing FieldTypes from SharePoint or other custom solutions. | FieldType | Warning |