Export (0) Print
Expand All
Expand Minimize

Creating Custom Extensions for SharePoint 2010 Development Tools in Visual Studio 2010

SharePoint 2010

SharePoint Visual How To

Summary:  Learn how to start creating custom extensions for the Microsoft SharePoint development tools in Microsoft Visual Studio 2010. By creating custom extensions, you can add your own SharePoint project templates and SharePoint Project Item templates into the Visual Studio 2010 development environment.

Last modified: September 12, 2012

Applies to: SharePoint Foundation 2010 | SharePoint Server 2010 | Visual Studio | Visual Studio 2008 | Visual Studio 2010

Provided by:  Ted Pattison, Critical Path Training, LLC (SharePoint MVP)

Overview

The Microsoft SharePoint development tools in Microsoft Visual Studio 2010 were designed to support extensibility. This SharePoint Visual How To demonstrates the basic steps of creating a Visual Studio 2010 project for creating a custom extension.

Code It

To create a custom extension for the new SharePoint development tools in Visual Studio 2010, you must first install both Visual Studio 2010 and the Visual Studio 2010 SDK. Installing the Visual Studio 2010 SDK adds a new Visual Studio project template named VSIX Project in the Extensibilty folder, as shown in Figure 1. This is the first project template that you should use when you want to create a custom extension for the SharePoint development tools in Visual Studio 2010.

Figure 1. VSIX Project template in Visual Studio

VSIX Project template in Visual Studio

When you build a VSIX project, the primary output is a VSIX file, which is used to distribute Visual Studio 2010 extensions to other developers. At a physical level, a VSIX file is a ZIP archive that contains a manifest and usually several additional components. These components can be assembly DLLs and internal ZIP archives that contain Visual Studio templates for creating new projects and project items.

Adding Code in a Class Library Project

After you create a new VSIX project, you must add your code somewhere. Although you can add class files for an extension directly into the VSIX project, the best practice is to add secondary Class Library projects into the same solution and have the output assembly DLLs from those projects built into the VSIX project. For example, if your VSIX project is named WingtipExtensions, you can add a second Class Library project, based on the Microsoft .NET Framework 4, named WingtipExtensions.Impl40.

To create a custom extension, you must create a class that implements one of eight different interfaces that were defined by the SharePoint tools team. You must also define this class with an Export attribute that is defined by a new framework in the .NET Framework 4 known as the Managed Extensibility Framework (MEF). Therefore, you must reference two assemblies in the Class Library DLL project that contains your extension class:

  1. First, you reference the assembly for the MEF named System.ComponentModel.Composition.dll so that you can use the Export attribute.

  2. Second, you add a reference to Microsoft.VisualStudio.SharePoint.dll so that you can implement one of the interfaces that are required to create an extension class.

You can implement the following eight extensibility interfaces.

  • ISharePointProjectExtension   Extend SharePoint project behavior.

  • ISharePointProjectItemTypeProvider   Create a new SharePoint Project Item template.

  • ISharePointProjectItemTypeExtension   Extend SharePoint Project Item behavior.

  • IExplorerNodeTypeProvider   Create a new SharePoint Explorer node type.

  • IExplorerNodeTypeExtension   Extend SharePoint Explorer node behavior.

  • IDeploymentStep   Create a custom deployment step.

  • IFeatureValidationRule   Create a feature validation rule.

  • IPackageValidationRule   Create a package validation rule.

After you select the type of extension that you want to create, you can create an extension class by implementing the interface and marking the class with the Export attribute parameterized with the same interface type, as shown in the following example. Some extensibility interfaces, such as ISharePointProjectItemTypeProvider, also require additional attributes.

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.SharePoint;

namespace WingtipExtensions.Impl40 {

  [Export(typeof(ISharePointProjectExtension))]
  public class WingtipProjectExtension : ISharePointProjectExtension {

    public void Initialize(ISharePointProjectService projectService) {
      projectService.Logger.WriteLine("Hello", LogCategory.Message);
    }
  }
}

Updating the Manifest File

The final step is to modify the VSIX project so that it builds the output assembly DLL of the other Class Library project into the VSIX file. You must also update the manifest file inside the VSIX project. This manifest, named source.extension.vsixmanifest, must be updated so that it recognizes the assembly DLL as a MEF component. Visual Studio contains a designer that makes performing these two steps very easy.

If you double-click source.extension.vsixmanifest, Visual Studio opens a designer that lets you add information about your extension. At the bottom of the manifest designer window, there is a Content section that contains an Add Content button. If you click this button, an Add Content dialog box appears (see Figure 2), where you can add the output of the Class Library project DLL as a MEF Component.

Figure 2. Add Content dialog box

Add Content dialog box

After you add the Class Library project into the Content section as a MEF Component (see Figure 3), Visual Studio makes the required changes to source.extension.vsixmanifest and configures the VSIX project to add the Class Library project DLL to the output VSIX file.

Figure 3. MEF Component added to Content section

MEF component added to Content section

Read It

The SharePoint development tools in Visual Studio 2010 provide an improved development experience for building business solutions in SharePoint 2010. By creating custom extensions for the SharePoint tools, you can add your own SharePoint project templates and SharePoint Project Item templates into the Visual Studio 2010 development environment.

See It

Watch the video

Watch video

Length: 00:10:14

Explore It

MVP Contributor Ted Pattison is an author, instructor, and co-founder of Critical Path Training, a company dedicated to education on SharePoint technologies. As a Microsoft SharePoint Most Valuable Professional (MVP), Ted frequently works with the Microsoft Developer Platform Evangelism group to research and author SharePoint training material for developers early in the product life cycle while in its alpha and beta stages. Ted is also co-author of Inside Microsoft SharePoint 2010.

Show:
© 2015 Microsoft