How to: Define a SharePoint Project Item Type

Define a project item type when you want to create a custom SharePoint project item. For more information, see Defining Custom SharePoint Project Item Types.

To define a project item type

  1. Create a class library project.

  2. Add references to the following assemblies:

    • Microsoft.VisualStudio.SharePoint

    • System.ComponentModel.Composition

  3. Create a class that implements the ISharePointProjectItemTypeProvider interface.

  4. Add the following attributes to the class:

    • ExportAttribute. This attribute enables Visual Studio to discover and load your ISharePointProjectItemTypeProvider implementation. Pass the ISharePointProjectItemTypeProvider type to the attribute constructor.

    • SharePointProjectItemTypeAttribute. In a project item type definition, this attribute specifies the string identifier for the new project item. We recommend that you use the format company name.feature name to help make sure that all project items have a unique name.

    • SharePointProjectItemIconAttribute. This attribute specifies the icon to display for this project item in Solution Explorer. This attribute is optional; if you do not apply it to your class, Visual Studio displays a default icon for your project item. If you set this attribute, pass the fully qualified name of an icon or bitmap that is embedded in your assembly.

  5. In your implementation of the InitializeType method, use members of the projectItemTypeDefinition parameter to define the behavior of the project item type. This parameter is an ISharePointProjectItemTypeDefinition object that provides access to the events defined in the ISharePointProjectItemEvents and ISharePointProjectItemFileEvents interfaces. To access a specific instance of your project item type, handle ISharePointProjectItemEvents events such as ProjectItemAdded and ProjectItemInitialized.

The following code example demonstrates how to define a simple project item type. This project item type writes a message to the Output window and Error List window when a user adds a project item of this type to a project.

using System;
using Microsoft.VisualStudio.SharePoint;
using System.ComponentModel.Composition;

namespace Contoso.ExampleProjectItemType
    internal class ExampleProjectItemType : ISharePointProjectItemTypeProvider
        public void InitializeType(ISharePointProjectItemTypeDefinition projectItemTypeDefinition)
            projectItemTypeDefinition.Name = "ExampleProjectItemType";
            projectItemTypeDefinition.SupportedDeploymentScopes =
                SupportedDeploymentScopes.Site | SupportedDeploymentScopes.Web;
            projectItemTypeDefinition.SupportedTrustLevels = SupportedTrustLevels.All;
            projectItemTypeDefinition.ProjectItemAdded += projectItemTypeDefinition_ProjectItemAdded;

        void projectItemTypeDefinition_ProjectItemAdded(object sender, SharePointProjectItemEventArgs e)
            string message = String.Format("An example project item named {0} was added to the {1} project.",
                e.ProjectItem.Name, e.ProjectItem.Project.Name);
            e.ProjectItem.Project.ProjectService.Logger.WriteLine(message, LogCategory.Message);

This example uses the SharePoint project service to write the message to the Output window and Error List window. For more information, see Using the SharePoint Project Service.

This example requires references to the following assemblies:

  • Microsoft.VisualStudio.SharePoint

  • System.ComponentModel.Composition

To enable other developers to use your project item, create a project template or a project item template. For more information, see Creating Item Templates and Project Templates for SharePoint Project Items.

To deploy the project item, create a Visual Studio extension (VSIX) package for the assembly, the template, and any other files that you want to distribute with the project item. For more information, see Deploying Extensions for the SharePoint Tools in Visual Studio.