We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

How to: Create a SharePoint Project Item Extension


Create a project item extension when you want to add functionality to a SharePoint project item that is already installed in Visual Studio. For more information, see Extending SharePoint Project Items.

To create a project item extension

  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 ISharePointProjectItemTypeExtension interface.

  4. Add the following attributes to the class:

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

The following code example demonstrates how to create a simple extension for the Event Receiver project item. Each time the user adds an Event Receiver project item to a SharePoint project, this extension writes a message to the Output window and Error List window.

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

namespace Contoso.ExampleProjectItemExtension
    internal class ExampleProjectItemExtension : ISharePointProjectItemTypeExtension
        public void Initialize(ISharePointProjectItemType projectItemType)
            projectItemType.ProjectItemAdded += projectItemType_ProjectItemAdded;

        void projectItemType_ProjectItemAdded(object sender, SharePointProjectItemEventArgs e)
            ISharePointProjectItem projectItem = (ISharePointProjectItem)sender;
            string message = String.Format("An Event Handler project item named {0} was added to the {1} project.",
                projectItem.Name, projectItem.Project.Name);
            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 deploy the extension, create a Visual Studio extension (VSIX) package for the assembly and any other files that you want to distribute with the extension. For more information, see Deploying Extensions for the SharePoint Tools in Visual Studio.

Extending SharePoint Project Items
Walkthrough: Extending a SharePoint Project Item Type