Share via


Converting Between SharePoint Project System Types and Other Visual Studio Project Types

In some cases you might have an object in the SharePoint project system and you want to use features of a corresponding object in the Visual Studio automation object model or integration object model, or vice versa. In these cases, you can use the Convert<TInput, TOutput> method of the SharePoint project service to convert the object to a different object model.

For example, you might have an ISharePointProject object, but you want to use methods that are only available on an EnvDTE.Project or Microsoft.VisualStudio.Shell.Interop.IVsProject object. In this case, you can use the Convert<TInput, TOutput> method to convert the ISharePointProject to an EnvDTE.Project or Microsoft.VisualStudio.Shell.Interop.IVsProject.

For more information about the Visual Studio automation object model and the Visual Studio integration object model, see Overview of the Programming Model of SharePoint Tools Extensions.

Types of Conversions

The following table lists the types that this method can convert between the SharePoint project system and the other Visual Studio object models.

SharePoint project system type

Corresponding types in the automation and integration object models

ISharePointProject

EnvDTE.Project

or

Any interface in the Visual Studio integration object model that is implemented by the underlying COM object for the project. These interfaces include Microsoft.VisualStudio.Shell.Interop.IVsHierarchy, Microsoft.VisualStudio.Shell.Interop.IVsProject (or a derived interface), and Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage. For a list of the main interfaces that are implemented by projects, see Project Model Core Components.

IMappedFolder

ISharePointProjectItem

ISharePointProjectItemFile

ISharePointProjectFeature

ISharePointProjectFeatureResourceFile

ISharePointProjectPackage

EnvDTE.ProjectItem

or

A UInt32 value (also called a VSITEMID) that identifies the project member in the Microsoft.VisualStudio.Shell.Interop.IVsHierarchy that contains it. This value can be passed to the itemid parameter of some Microsoft.VisualStudio.Shell.Interop.IVsHierarchy methods.

Example

The following code example demonstrates how to use the Convert<TInput, TOutput> method to convert an ISharePointProject object to an EnvDTE.Project.

Private Sub projectService_ProjectAdded(ByVal sender As Object, _
    ByVal e As Microsoft.VisualStudio.SharePoint.SharePointProjectEventArgs)

    Dim dteProject As EnvDTE.Project = e.Project.ProjectService.Convert( _
        Of Microsoft.VisualStudio.SharePoint.ISharePointProject, EnvDTE.Project)(e.Project)
    If dteProject IsNot Nothing Then 
        ' Use the Visual Studio automation object model to add a folder to the project.
        dteProject.ProjectItems.AddFolder("Data")
    End If 
End Sub
void projectService_ProjectAdded(object sender, Microsoft.VisualStudio.SharePoint.SharePointProjectEventArgs e)
{
    EnvDTE.Project dteProject = e.Project.ProjectService.Convert<
        Microsoft.VisualStudio.SharePoint.ISharePointProject, EnvDTE.Project>(e.Project);

    if (dteProject != null)
    {
        // Use the Visual Studio automation object model to add a folder to the project.
        dteProject.ProjectItems.AddFolder("Data");
    }
}

This example requires:

See Also

Concepts

Using the SharePoint Project Service

How to: Retrieve the SharePoint Project Service

Overview of the Programming Model of SharePoint Tools Extensions