방법: SharePoint 프로젝트 서비스 검색

다음 솔루션 형식의 SharePoint 프로젝트 서비스에 액세스할 수 있습니다.

  • 프로젝트 확장, 프로젝트 항목 확장, 프로젝트 항목 형식 정의 등의 SharePoint 프로젝트 시스템 확장. 이러한 확장 형식에 대한 자세한 내용은 SharePoint 프로젝트 시스템 확장을 참조하십시오.

  • 서버 탐색기에서 SharePoint 연결 노드의 확장. 이러한 확장 형식에 대한 자세한 내용은 서버 탐색기에서 SharePoint 연결 노드 확장을 참조하십시오.

  • 추가 기능 또는 VSPackage 같은 Visual Studio 확장의 다른 형식

프로젝트 시스템 확장에서 서비스 검색

SharePoint 프로젝트 시스템 확장에서 ISharePointProject 개체의 ProjectService 속성을 사용하여 프로젝트 서비스에 액세스할 수 있습니다.

다음 절차에 따라 프로젝트 서비스를 검색할 수도 있습니다.

프로젝트 확장에서 서비스를 검색하려면

  1. ISharePointProjectExtension 인터페이스의 구현에서 Initialize 메서드를 찾습니다.

  2. projectService 속성을 사용하여 서비스에 액세스합니다.

    다음 코드 예제에서는 간단한 프로젝트 확장에서 프로젝트 서비스를 사용하여 출력 창 및 오류 목록 창에 메시지를 작성하는 방법을 보여 줍니다.

    <Export(GetType(ISharePointProjectExtension))> _
    Friend Class GetServiceInProject
        Implements ISharePointProjectExtension
    
        Private Sub Initialize(ByVal projectService As ISharePointProjectService) _
            Implements ISharePointProjectExtension.Initialize
            projectService.Logger.WriteLine("This message was written by using the " & _
                "project service in a project extension.", LogCategory.Message)
        End Sub
    End Class
    
    [Export(typeof(ISharePointProjectExtension))]
    internal class GetServiceInProject : ISharePointProjectExtension
    {
        public void Initialize(ISharePointProjectService projectService)
        {
            projectService.Logger.WriteLine("This message was written by using the " +
                "project service in a project extension.", LogCategory.Message);
        }
    }
    

    프로젝트 확장 만들기에 대한 자세한 내용은 방법: SharePoint 프로젝트 확장 만들기를 참조하십시오.

프로젝트 항목 확장에서 서비스를 검색하려면

  1. ISharePointProjectItemTypeExtension 인터페이스의 구현에서 Initialize 메서드를 찾습니다.

  2. projectItemType 매개 변수의 ProjectService 속성을 사용하여 서비스를 검색합니다.

    다음 코드 예제에서는 목록 정의 프로젝트 항목의 간단한 확장에서 프로젝트 서비스를 사용하여 출력 창 및 오류 목록 창에 메시지를 작성하는 방법을 보여 줍니다.

    <Export(GetType(ISharePointProjectItemTypeExtension))> _
    <SharePointProjectItemType("Microsoft.VisualStudio.SharePoint.ListDefinition")> _
    Friend Class GetServiceInProjectItem
        Implements ISharePointProjectItemTypeExtension
    
        Private Sub Initialize(ByVal projectItemType As ISharePointProjectItemType) _
            Implements ISharePointProjectItemTypeExtension.Initialize
            projectItemType.ProjectService.Logger.WriteLine("This message was written " & _
                "by using the project service in an extension for the ListDefinition project item.", _
                LogCategory.Message)
        End Sub
    End Class
    
    [Export(typeof(ISharePointProjectItemTypeExtension))]
    [SharePointProjectItemType("Microsoft.VisualStudio.SharePoint.ListDefinition")]
    internal class GetServiceInProjectItem : ISharePointProjectItemTypeExtension
    {
        public void Initialize(ISharePointProjectItemType projectItemType)
        {
            projectItemType.ProjectService.Logger.WriteLine("This message was written " +
                "by using the project service in an extension for the ListDefinition project item.", 
                LogCategory.Message);
        }
    }
    

    프로젝트 항목 확장 만들기에 대한 자세한 내용은 방법: SharePoint 항목 확장 만들기를 참조하십시오.

프로젝트 항목 형식 정의에서 서비스를 검색하려면

  1. ISharePointProjectItemTypeProvider 인터페이스의 구현에서 InitializeType 메서드를 찾습니다.

  2. typeDefinition 매개 변수의 ProjectService 속성을 사용하여 서비스를 검색합니다.

    다음 코드 예제에서는 간단한 프로젝트 항목 형식 정의에서 프로젝트 서비스를 사용하여 출력 창 및 오류 목록 창에 메시지를 작성하는 방법을 보여 줍니다.

    <Export(GetType(ISharePointProjectItemTypeProvider))> _
    <SharePointProjectItemType("Contoso.CustomAction")> _
    Friend Class CustomActionProvider
        Implements ISharePointProjectItemTypeProvider
    
        Private Sub InitializeType(ByVal projectItemTypeDefinition As ISharePointProjectItemTypeDefinition) _
            Implements ISharePointProjectItemTypeProvider.InitializeType
            projectItemTypeDefinition.ProjectService.Logger.WriteLine("This message was written " & _
                "by using the project service in the Custom Action project item type.", _
                LogCategory.Message)
        End Sub
    End Class
    
    [Export(typeof(ISharePointProjectItemTypeProvider))]
    [SharePointProjectItemType("Contoso.CustomAction")]
    internal class CustomActionProvider : ISharePointProjectItemTypeProvider
    {
        public void InitializeType(ISharePointProjectItemTypeDefinition projectItemTypeDefinition)
        {
            projectItemTypeDefinition.ProjectService.Logger.WriteLine("This message was written " +
                "by using the project service in the Custom Action project item type definition.",
                LogCategory.Message);
        }
    }
    

    프로젝트 항목 형식 정의에 대한 자세한 내용은 방법: SharePoint 프로젝트 항목 형식 정의를 참조하십시오.

서버 탐색기 확장에서 서비스 검색

서버 탐색기에 있는 SharePoint 연결 노드의 확장에서 IExplorerNode 개체의 ServiceProvider 속성을 사용하여 프로젝트 서비스에 액세스할 수 있습니다.

서버 탐색기 확장에서 서비스를 검색하려면

  1. 확장에 있는 IExplorerNode 개체의 ServiceProvider 속성에서 IServiceProvider 개체를 가져옵니다.

  2. GetService 메서드를 사용하여 ISharePointProjectService 개체를 요청합니다.

    다음 코드 예제에서는 서버 탐색기의 노드를 나열하기 위해 확장을 통해 추가된 바로 가기 메뉴에서 프로젝트 서비스를 사용하여 출력 창 및 오류 목록 창에 메시지를 작성하는 방법을 보여 줍니다.

    <Export(GetType(IExplorerNodeTypeExtension))> _
    <ExplorerNodeType(ExtensionNodeTypes.ListNode)> _
    Friend Class ListNodeExtension
        Implements IExplorerNodeTypeExtension
    
        Private projectService As ISharePointProjectService
    
        Private Sub Initialize(ByVal nodeType As IExplorerNodeType) _
            Implements IExplorerNodeTypeExtension.Initialize
            AddHandler nodeType.NodeMenuItemsRequested, AddressOf nodeType_NodeMenuItemsRequested
        End Sub
    
        Private Sub nodeType_NodeMenuItemsRequested(ByVal Sender As Object, ByVal e As ExplorerNodeMenuItemsRequestedEventArgs)
            Dim writeMessageMenuItem As IMenuItem = e.MenuItems.Add("Write Message to Output Window and Error List Window")
            AddHandler writeMessageMenuItem.Click, AddressOf writeMessageMenuItem_Click
        End Sub
    
        Private Sub writeMessageMenuItem_Click(ByVal Sender As Object, ByVal e As MenuItemEventArgs)
            Dim node As IExplorerNode = CType(e.Owner, IExplorerNode)
            If projectService Is Nothing Then
                projectService = CType(node.ServiceProvider.GetService(GetType(ISharePointProjectService)), ISharePointProjectService)
            End If
            projectService.Logger.WriteLine("Clicked the menu item for " + node.Text, LogCategory.Message)
        End Sub
    End Class
    
    [Export(typeof(IExplorerNodeTypeExtension))]
    [ExplorerNodeType(ExtensionNodeTypes.ListNode)]
    internal class ListNodeExtension : IExplorerNodeTypeExtension
    {
        private ISharePointProjectService projectService;
    
        public void Initialize(IExplorerNodeType nodeType)
        {
            nodeType.NodeMenuItemsRequested += nodeType_NodeMenuItemsRequested;
        }
    
        void nodeType_NodeMenuItemsRequested(object sender, ExplorerNodeMenuItemsRequestedEventArgs e)
        {
            IMenuItem writeMessageMenuItem = e.MenuItems.Add("Write Message to Output Window and Error List Window");
            writeMessageMenuItem.Click += writeMessageMenuItem_Click;
        }
    
        void writeMessageMenuItem_Click(object sender, MenuItemEventArgs e)
        {
            IExplorerNode node = (IExplorerNode)e.Owner;
            if (projectService == null)
            {
                projectService = (ISharePointProjectService)node.ServiceProvider.GetService(typeof(ISharePointProjectService));
            }
    
            projectService.Logger.WriteLine("Clicked the menu item for " + node.Text, LogCategory.Message);
        }
    }
    

    서버 탐색기에서 SharePoint 연결 노드를 확장하는 방법에 대한 자세한 내용은 방법: 서버 탐색기에서 SharePoint 노드 확장을 참조하십시오.

기타 Visual Studio 확장에서 서비스 검색

VSPackage에서 프로젝트 서비스를 검색하거나, 자동화 개체 모델의 EnvDTE80.DTE2 개체에 액세스하는 Visual Studio 확장(예: Microsoft.VisualStudio.TemplateWizard.IWizard 인터페이스를 구현하는 추가 기능 또는 프로젝트 템플릿 마법사)에서 서비스를 검색할 수 있습니다.

VSPackage에서는 다음 메서드 중 하나를 사용하여 ISharePointProjectService 개체를 요청할 수 있습니다.

EnvDTE80.DTE2 개체에 액세스하는 Visual Studio 확장에서 Microsoft.VisualStudio.Shell.ServiceProvider 개체의 GetService() 메서드를 사용하여 ISharePointProjectService 개체를 요청할 수 있습니다. 자세한 내용은 How to: Get a Service from the DTE Object를 참조하십시오.

예제

다음 코드 예제에서는 Visual Studio 추가 기능에서 프로젝트 서비스를 검색하는 방법을 보여 줍니다. 이 코드를 사용하려면 추가 기능 프로젝트의 Connect 클래스에서 이 코드를 실행하십시오. 추가 기능 프로젝트에서 _applicationObject 개체는 자동으로 생성되며, 이 개체는 EnvDTE80.DTE2 인터페이스의 인스턴스입니다.

Dim serviceProvider As Microsoft.VisualStudio.Shell.ServiceProvider = _
    New Microsoft.VisualStudio.Shell.ServiceProvider( _
        TryCast(_applicationObject, Microsoft.VisualStudio.OLE.Interop.IServiceProvider))

Dim projectService As Microsoft.VisualStudio.SharePoint.ISharePointProjectService = _
    TryCast(serviceProvider.GetService(GetType(Microsoft.VisualStudio.SharePoint.ISharePointProjectService)), _
        Microsoft.VisualStudio.SharePoint.ISharePointProjectService)

If projectService IsNot Nothing Then
    projectService.Logger.WriteLine("This message was written by using the SharePoint project service.", _
        Microsoft.VisualStudio.SharePoint.LogCategory.Message)
End If
Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider =
    new Microsoft.VisualStudio.Shell.ServiceProvider(
    _applicationObject as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);

Microsoft.VisualStudio.SharePoint.ISharePointProjectService projectService = 
    serviceProvider.GetService(typeof(Microsoft.VisualStudio.SharePoint.ISharePointProjectService))
    as Microsoft.VisualStudio.SharePoint.ISharePointProjectService;

if (projectService != null)
{
    projectService.Logger.WriteLine("This message was written by using the SharePoint project service.",
        Microsoft.VisualStudio.SharePoint.LogCategory.Message);
}

이 예제에는 다음 사항이 필요합니다.

  • Visual Studio 추가 기능 프로젝트. 자세한 내용은 방법: 추가 기능 만들기를 참조하십시오.

  • Microsoft.VisualStudio.OLE.Interop, Microsoft.VisualStudio.Shell 및 Microsoft.VisualStudio.SharePoint 어셈블리에 대한 참조

참고 항목

작업

방법: 추가 기능 만들기

How to: Consume a Service

How to: Get a Service from the DTE Object

방법: 프로젝트 템플릿에 마법사 사용

개념

SharePoint 프로젝트 서비스 사용