Partilhar via


Extend SharePoint project items

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Create a project item extension when you want to add functionality to a type of SharePoint project item that is already installed in Visual Studio. For example, you can create an extension for the built-in Event Receiver or List Definition project items in Visual Studio, or you can create an extension for a custom project item type. You can also create an extension for all types of SharePoint project items.

Tasks for extending SharePoint project items

To extend a project item, build a Visual Studio extension assembly that implements the ISharePointProjectItemTypeExtension interface. For more information, see How to: Create a SharePoint project item extension.

When you extend a project item, you can also add the following functionality to the project item:

Understand the relationship between project item extensions and project item instances

When you create a project item extension, Visual Studio loads your extension when a project item of the associated type is added to a SharePoint project. For example, if you create an extension for Event Receiver project items, Visual Studio loads your extension when a user adds an Event Receiver project item to a project. Visual Studio uses the same instance of your extension for all instances of the associated project item type. In the previous example, if the user adds a second Event Receiver project item to the project, the same instance of your extension is used to customize the second project item.

To access a specific instance of the project item type you are extending, handle one of the ISharePointProjectItemEvents events of the projectItemType parameter in your implementation of the Initialize method. For example, to determine when a project item of the type you are extending is added to a project, handle the ProjectItemAdded event. For more information, see How to: Create a SharePoint project item extension.

Identifiers for SharePoint project items

Each SharePoint project item has a corresponding string identifier. You must know the identifier for a project item if you want to perform the following tasks:

  • Create an extension for the project item. In this case, you must pass the identifier for the project item that you want to extend to the constructor of the SharePointProjectItemTypeAttribute. To create an extension for all project item types, pass the \* string value.

  • Add the project item to a project programmatically. In this case, you must pass the identifier for the project item to the Add method.

    The following table lists the identifiers for the SharePoint project items that are included with Visual Studio.

Project item name String identifier
Business Data Catalog Model Microsoft.VisualStudio.SharePoint.BusinessDataConnectivity
Content Type Microsoft.VisualStudio.SharePoint.ContentType
Event Receiver Microsoft.VisualStudio.SharePoint.EventHandler
Empty Element Microsoft.VisualStudio.SharePoint.GenericElement
List Definition

List Definition From Content Type
Microsoft.VisualStudio.SharePoint.ListDefinition
List Instance Microsoft.VisualStudio.SharePoint.ListInstance
Module Microsoft.VisualStudio.SharePoint.Module
Sequential Workflow

State Machine Workflow
Microsoft.VisualStudio.SharePoint.Workflow
Site Definition Microsoft.VisualStudio.SharePoint.SiteDefinition
Visual Web Part Microsoft.VisualStudio.SharePoint.VisualWebPart
Web Part Microsoft.VisualStudio.SharePoint.WebPart
Workflow Association Form Microsoft.VisualStudio.SharePoint.WorkflowAssociation

See also