다음을 통해 공유


연습: 서버 탐색기를 확장하여 웹 파트 표시

Visual Studio 2010에서는 서버 탐색기SharePoint 연결 노드를 사용하여 SharePoint 사이트의 구성 요소를 볼 수 있습니다. 그러나 서버 탐색기의 일부 구성 요소는 기본적으로 표시되지 않습니다. 이 연습에서는 연결된 각 SharePoint 사이트의 웹 파트 갤러리를 표시하도록 서버 탐색기를 확장합니다.

이 연습에서는 다음 작업을 수행합니다.

  • 다음과 같은 방법으로 서버 탐색기를 확장하는 Visual Studio 확장 만들기

    • 서버 탐색기의 각 SharePoint 사이트 노드 아래에 새 웹 파트 갤러리 노드를 추가합니다. 새 노드에는 사이트에서 웹 파트 갤러리의 각 웹 파트를 나타내는 자식 노드가 포함됩니다.

    • 웹 파트 인스턴스를 나타내는 새 노드 형식을 정의합니다. 새 노드 형식은 새 웹 파트 갤러리 노드 아래에 있는 자식 노드의 기반이 됩니다. 새 웹 파트 노드 형식이 나타내는 웹 파트에 대한 정보가 속성 창에 표시됩니다. 노드 형식에는 웹 파트와 관련된 기타 작업을 위한 시작점으로 사용할 수 있는 사용자 지정 바로 가기 메뉴 항목도 포함됩니다.

  • 확장 어셈블리를 통해 호출되는 두 개의 사용자 지정 SharePoint 명령 만들기. SharePoint 명령은 확장 어셈블리가 SharePoint 서버 개체 모델에서 API를 사용하기 위해 호출할 수 있는 메서드입니다. 이 연습에서는 개발 컴퓨터의 로컬 SharePoint 사이트로부터 웹 파트 정보를 검색하는 명령을 만듭니다. 자세한 내용은 SharePoint 개체 모델 호출을 참조하십시오.

  • 확장을 배포하기 위한 VSIX(Visual Studio Extension) 패키지 빌드

  • 확장 디버깅 및 테스트

참고

이 연습의 다른 버전으로서 서버 개체 모델 대신 SharePoint 클라이언트 개체 모델을 사용하는 방법은 연습: 서버 탐색기 확장의 SharePoint 클라이언트 개체 모델 호출을 참조하십시오.

사전 요구 사항

이 연습을 완료하려면 개발 컴퓨터에 다음 구성 요소가 필요합니다.

다음 개념을 알고 있으면 연습을 완료하는 데 도움이 되지만 반드시 필요하지는 않습니다.

프로젝트 만들기

이 연습을 완료하려면 세 프로젝트를 만들어야 합니다.

  • VSIX 패키지를 만들어 확장을 배포하기 위한 VSIX 프로젝트

  • 확장을 구현하는 클래스 라이브러리 프로젝트. 이 프로젝트는 .NET Framework 4를 대상으로 해야 합니다.

  • 사용자 지정 SharePoint 명령을 정의하는 클래스 라이브러리 프로젝트. 이 프로젝트는 .NET Framework 3.5를 대상으로 해야 합니다.

먼저 프로젝트를 만들어 연습을 시작합니다.

VSIX 프로젝트를 만들려면

  1. Visual Studio를 시작합니다.

  2. 파일 메뉴에서 새로 만들기를 가리킨 다음 프로젝트를 클릭합니다.

  3. 새 프로젝트 대화 상자에서 Visual C# 또는 Visual Basic 노드를 확장한 다음 확장성 노드를 선택합니다.

    참고

    확장성 노드는 Visual Studio 2010 SDK를 설치한 경우에만 사용할 수 있습니다. 자세한 내용은 위의 필수 구성 요소 단원을 참조하십시오.

  4. 대화 상자 맨 위의 콤보 상자에서 .NET Framework 4를 선택합니다.

  5. VSIX 프로젝트 템플릿을 선택합니다.

  6. 이름 상자에 WebPartNode를 입력합니다.

  7. 확인을 클릭합니다.

    Visual Studio에서 솔루션 탐색기WebPartNode 프로젝트를 추가합니다.

확장 프로젝트를 만들려면

  1. 솔루션 탐색기에서 솔루션 노드를 마우스 오른쪽 단추로 클릭한 다음 추가, 새 프로젝트를 차례로 클릭합니다.

    참고

    Visual Basic 프로젝트에서는 옵션 대화 상자, 프로젝트 및 솔루션, 일반에서 솔루션 항상 표시 확인란을 선택한 경우에만 솔루션 탐색기에 솔루션 노드가 표시됩니다.

  2. 새 프로젝트 대화 상자에서 Visual C# 또는 Visual Basic 노드를 확장하고 Windows를 클릭합니다.

  3. 대화 상자 맨 위의 콤보 상자에서 .NET Framework 4를 선택합니다.

  4. 클래스 라이브러리 프로젝트 템플릿을 선택합니다.

  5. 이름 상자에 WebPartNodeExtension을 입력합니다.

  6. 확인을 클릭합니다.

    Visual Studio에서 솔루션에 WebPartNodeExtension 프로젝트를 추가하고 기본 Class1 코드 파일을 엽니다.

  7. 프로젝트에서 Class1 코드 파일을 삭제합니다.

SharePoint 명령 프로젝트를 만들려면

  1. 솔루션 탐색기에서 솔루션 노드를 마우스 오른쪽 단추로 클릭한 다음 추가, 새 프로젝트를 차례로 클릭합니다.

    참고

    Visual Basic 프로젝트에서는 옵션 대화 상자, 프로젝트 및 솔루션, 일반에서 솔루션 항상 표시 확인란을 선택한 경우에만 솔루션 탐색기에 솔루션 노드가 표시됩니다.

  2. 새 프로젝트 대화 상자에서 Visual C# 또는 Visual Basic 노드를 확장하고 Windows를 클릭합니다.

  3. 대화 상자 맨 위의 콤보 상자에서 .NET Framework 3.5를 선택합니다.

  4. 클래스 라이브러리 프로젝트 템플릿을 선택합니다.

  5. 이름 상자에 WebPartCommands를 입력합니다.

  6. 확인을 클릭합니다.

    Visual Studio에서 솔루션에 WebPartCommands 프로젝트를 추가하고 기본 Class1 클래스 파일을 엽니다.

  7. 프로젝트에서 Class1 코드 파일을 삭제합니다.

프로젝트 구성

확장을 만드는 코드를 작성하기 전에 코드 파일과 어셈블리 참조를 추가하고 프로젝트 설정을 구성해야 합니다.

WebPartNodeExtension 프로젝트를 구성하려면

  1. WebPartNodeExtension 프로젝트에서 다음과 같은 이름의 코드 파일 네 개를 추가합니다.

    • SiteNodeExtension

    • WebPartNodeTypeProvider

    • WebPartNodeInfo

    • WebPartCommandIds

  2. 프로젝트 메뉴에서 참조 추가를 클릭합니다.

  3. .NET 탭에서 Ctrl 키를 누르고 다음 어셈블리를 선택한 다음 확인을 클릭합니다.

    • Microsoft.VisualStudio.SharePoint

    • System.ComponentModel.Composition

    • System.Windows.Forms

  4. 솔루션 탐색기에서 WebPartNodeExtension 프로젝트 노드를 마우스 오른쪽 단추로 클릭한 다음 속성을 선택합니다.

    프로젝트 디자이너가 열립니다.

  5. 응용 프로그램 탭을 클릭합니다.

  6. 기본 네임스페이스 상자(C#) 또는 루트 네임스페이스 상자(Visual Basic)에 ServerExplorer.SharePointConnections.WebPartNode를 입력합니다.

WebPartCommands 프로젝트를 구성하려면

  1. WebPartCommands 프로젝트에 WebPartCommands라는 코드 파일을 추가합니다.

  2. 솔루션 탐색기에서 WebPartCommands 프로젝트 노드를 선택합니다.

  3. 프로젝트 메뉴에서 기존 항목 추가를 선택합니다.

  4. 기존 항목 추가 대화 상자에서 WebPartNodeExtension 프로젝트의 코드 파일이 포함된 폴더로 이동합니다.

  5. WebPartNodeInfo 및 WebPartCommandIds 코드 파일을 선택합니다.

  6. 추가 단추의 드롭다운 메뉴를 클릭하고 링크로 추가를 선택합니다.

    Visual Studio에서 코드 파일을 WebPartCommands 프로젝트에 링크로 추가합니다. 즉, 코드 파일은 WebPartNodeExtension 프로젝트에 있지만 파일의 코드는 WebPartCommands 프로젝트에도 컴파일됩니다.

  7. 프로젝트 메뉴에서 참조 추가를 클릭합니다.

  8. .NET 탭에서 Ctrl 키를 누르고 다음 어셈블리를 선택한 다음 확인을 클릭합니다.

    • Microsoft.SharePoint

    • Microsoft.VisualStudio.SharePoint.Commands

  9. 솔루션 탐색기에서 WebPartCommands 프로젝트 노드를 마우스 오른쪽 단추로 클릭한 다음 속성을 선택합니다.

    프로젝트 디자이너가 열립니다.

  10. 응용 프로그램 탭을 클릭합니다.

  11. 기본 네임스페이스 상자(C#) 또는 루트 네임스페이스 상자(Visual Basic)에 ServerExplorer.SharePointConnections.WebPartNode를 입력합니다.

새 노드의 아이콘 만들기

서버 탐색기 확장에 대한 두 아이콘을 만듭니다. 한 아이콘은 새 웹 파트 갤러리 노드를 나타내고, 다른 아이콘은 웹 파트 갤러리 노드 아래의 각 자식 웹 파트 노드를 나타냅니다. 이 연습의 뒷부분에서는 이러한 아이콘을 노드에 연결하는 코드를 작성합니다.

노드의 아이콘을 만들려면

  1. 솔루션 탐색기에서 WebPartNodeExtension 프로젝트 노드를 마우스 오른쪽 단추로 클릭한 다음 속성을 선택합니다.

  2. 프로젝트 메뉴에서 WebPartNodeExtension 속성을 선택합니다.

    프로젝트 디자이너가 열립니다.

  3. 리소스 탭을 클릭합니다.

  4. **이 프로젝트에는 기본 리소스 파일이 없습니다. 기본 리소스 파일을 만들려면 여기를 클릭하십시오.**를 클릭합니다.

    Visual Studio에서 리소스 파일을 만들어 디자이너에서 엽니다.

  5. 디자이너의 맨 위에 있는 추가 단추의 드롭다운 화살표를 클릭한 다음 새 아이콘 추가를 클릭합니다.

  6. 새 아이콘 이름으로 WebPartsNode를 입력하고 추가를 클릭합니다.

    새 아이콘이 이미지 편집기에서 열립니다.

  7. 디자인을 쉽게 인식할 수 있도록 16x16 버전의 아이콘 파일을 편집합니다.

  8. 32x32 버전의 아이콘을 선택합니다.

  9. 이미지 메뉴에서 이미지 형식 삭제를 선택합니다.

  10. 5-9단계를 반복하여 프로젝트 리소스에 두 번째 아이콘을 추가합니다. 이 아이콘의 이름을 WebPart로 지정합니다.

  11. 솔루션 탐색기에서 WebPartNodeExtension 프로젝트의 리소스 폴더 아래에 있는 WebPartsNode.ico를 선택합니다.

  12. 속성 창에서 빌드 작업 옆에 있는 드롭다운을 클릭한 다음 포함 리소스를 선택합니다.

  13. WebPart.ico에 대해 마지막 두 단계를 반복합니다.

서버 탐색기에 웹 파트 갤러리 노드 추가

각 SharePoint 사이트 노드에 새 웹 파트 갤러리 노드를 추가하는 클래스를 만듭니다. 새 코드를 추가하기 위해 클래스에서 IExplorerNodeTypeExtension 인터페이스를 구현합니다. 노드에 새 자식 노드 추가 등 서버 탐색기에서 기존 노드의 동작을 확장하려는 경우 이 인터페이스를 구현합니다.

서버 탐색기에 웹 파트 갤러리 노드를 추가하려면

  1. WebPartNodeExtension 프로젝트에서 SiteNodeExtension 코드 파일을 두 번 클릭합니다.

  2. 이 파일에 다음 코드를 붙여 넣습니다.

    참고

    이 코드를 추가하면 프로젝트에서 컴파일 오류가 발생합니다. 이러한 오류는 이후 단계에서 코드를 추가하면 사라집니다.

    Imports System.Collections.Generic
    Imports System.ComponentModel.Composition
    Imports Microsoft.VisualStudio.SharePoint.Explorer
    
    Namespace ServerExplorer.SharePointConnections.WebPartNode
    
        ' Export attribute: Enables Visual Studio to discover and load this extension.
        ' ExplorerNodeType attribute:  Indicates that this class extends SharePoint site nodes in Server Explorer.
        ' WebPartNodeTypeProvider class: Represents an extension of SharePoint site nodes in Server Explorer.
        <Export(GetType(IExplorerNodeTypeExtension))> _
        <ExplorerNodeType(ExplorerNodeTypes.SiteNode)> _
        Friend Class SiteNodeExtension
            Implements IExplorerNodeTypeExtension
    
            Private Sub Initialize(ByVal nodeType As IExplorerNodeType) _
                Implements IExplorerNodeTypeExtension.Initialize
    
                ' The NodeChildrenRequested event is raised when the user expands the
                ' SharePoint site node in Server Explorer.
                AddHandler nodeType.NodeChildrenRequested, AddressOf NodeChildrenRequested
            End Sub
    
            ' Creates the new Web Part Gallery node with the specified icon.
            Private Sub NodeChildrenRequested(ByVal Sender As Object, ByVal e As ExplorerNodeEventArgs)
    
                ' The CreateWebPartNodes argument is a delegate that Visual Studio calls 
                ' to create the child nodes under the Web Part Gallery node.
                e.Node.ChildNodes.AddFolder("Web Part Gallery", My.Resources.WebPartsNode.ToBitmap(), _
                    AddressOf CreateWebPartNodes)
            End Sub
    
            ' Creates all of the individual Web Part nodes under the new Web Part Gallery node.
            Private Sub CreateWebPartNodes(ByVal parentNode As IExplorerNode)
    
                ' Call the custom SharePoint command to get items from the Web Part gallery.
                Dim webParts = parentNode.Context.SharePointConnection.ExecuteCommand(Of WebPartNodeInfo())( _
                    WebPartCommandIds.GetWebParts)
                If webParts IsNot Nothing Then
                    For Each webPart As WebPartNodeInfo In webParts
    
                        ' Create a new annotation object to store the current Web Part item with the new node.
                        Dim annotations = New Dictionary(Of Object, Object)()
                        annotations.Add(GetType(WebPartNodeInfo), webPart)
    
                        ' Create the new node for the current Web Part item.
                        parentNode.ChildNodes.Add(WebPartNodeTypeProvider.WebPartNodeTypeId, _
                            webPart.Name, annotations)
                    Next
                End If
            End Sub
    
        End Class
    End Namespace
    
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using Microsoft.VisualStudio.SharePoint.Explorer;
    
    namespace ServerExplorer.SharePointConnections.WebPartNode
    {
        // Enables Visual Studio to discover and load this extension.
        [Export(typeof(IExplorerNodeTypeExtension))]        
    
        // Indicates that this class extends SharePoint site nodes in Server Explorer.
        [ExplorerNodeType(ExplorerNodeTypes.SiteNode)]
    
        // Represents an extension of SharePoint site nodes in Server Explorer.
        internal class SiteNodeExtension : IExplorerNodeTypeExtension
        {
            public void Initialize(IExplorerNodeType nodeType)
            {
                // The NodeChildrenRequested event is raised when the user expands the
                // SharePoint site node in Server Explorer.
                nodeType.NodeChildrenRequested += NodeChildrenRequested;
            }
    
            // Creates the new Web Part Gallery node with the specified icon.
            private void NodeChildrenRequested(object sender, ExplorerNodeEventArgs e)
            {
                // The CreateWebPartNodes argument is a delegate that Visual Studio calls 
                // to create the child nodes under the Web Part Gallery node.
                e.Node.ChildNodes.AddFolder("Web Part Gallery",
                    Properties.Resources.WebPartsNode.ToBitmap(), CreateWebPartNodes);
            }
    
            // Creates all of the individual Web Part nodes under the new Web Part Gallery node.
            private void CreateWebPartNodes(IExplorerNode parentNode)
            {
                // Call the custom SharePoint command to get items from the Web Part gallery.
                var webParts = parentNode.Context.SharePointConnection.ExecuteCommand<WebPartNodeInfo[]>(
                    WebPartCommandIds.GetWebParts);
    
                if (webParts != null)
                {
                    foreach (WebPartNodeInfo webPart in webParts)
                    {
                        // Create a new annotation object to store the current Web Part item with the new node.
                        var annotations = new Dictionary<object, object>() 
                        { 
                            { typeof(WebPartNodeInfo), webPart } 
                        };
    
                        // Create the new node for the current Web Part item.
                        parentNode.ChildNodes.Add(WebPartNodeTypeProvider.WebPartNodeTypeId,
                            webPart.Name, annotations);
                    }
                }
            }
        }
    }
    

웹 파트를 나타내는 노드 형식 정의

웹 파트를 나타내는 새 노드 형식을 정의하는 클래스를 만듭니다. 새 노드 형식은 Visual Studio에서 웹 파트 갤러리 노드 아래에 자식 노드를 표시하는 데 사용됩니다. 이러한 각 자식 노드는 SharePoint 사이트에서 하나의 웹 파트를 나타냅니다.

새 노드 형식을 정의하기 위해 클래스에서 IExplorerNodeTypeProvider 인터페이스를 구현합니다. 서버 탐색기에서 새 노드 형식을 정의하려는 경우 이 인터페이스를 구현합니다.

웹 파트 노드 형식을 정의하려면

  1. WebPartNodeExtension 프로젝트에서 WebPartNodeTypeProvder 코드 파일을 두 번 클릭합니다.

  2. 이 파일에 다음 코드를 붙여 넣습니다.

    Imports System
    Imports System.Collections.Generic
    Imports System.Windows.Forms
    Imports System.ComponentModel.Composition
    Imports Microsoft.VisualStudio.SharePoint
    Imports Microsoft.VisualStudio.SharePoint.Explorer
    
    Namespace ServerExplorer.SharePointConnections.WebPartNode
    
        ' Export attribute: Enables Visual Studio to discover and load this extension.
        ' ExplorerNodeType attribute: Specifies the ID for this new node type.
        ' WebPartNodeTypeProvider class: Defines a new node type that represents a Web Part on a SharePoint site.
        <Export(GetType(IExplorerNodeTypeProvider))> _
        <ExplorerNodeType(WebPartNodeTypeProvider.WebPartNodeTypeId)> _
        Friend Class WebPartNodeTypeProvider
            Implements IExplorerNodeTypeProvider
    
            Friend Const WebPartNodeTypeId As String = "Contoso.WebPart"
    
            Private Sub InitializeType(ByVal typeDefinition As IExplorerNodeTypeDefinition) _
                Implements IExplorerNodeTypeProvider.InitializeType
    
                typeDefinition.DefaultIcon = My.Resources.WebPart.ToBitmap()
                typeDefinition.IsAlwaysLeaf = True
                AddHandler typeDefinition.NodePropertiesRequested, AddressOf NodePropertiesRequested
            End Sub
    
            ' Retrieves properties that are displayed in the Properties window when
            ' a Web Part node is selected.
            Private Sub NodePropertiesRequested(ByVal Sernder As Object, _
                ByVal e As ExplorerNodePropertiesRequestedEventArgs)
    
                Dim nodeInfo = e.Node.Annotations.GetValue(Of WebPartNodeInfo)()
    
                ' Call the custom SharePoint command to get the Web Part properties.
                Dim properties As Dictionary(Of String, String) = _
                    e.Node.Context.SharePointConnection.ExecuteCommand( _
                    Of WebPartNodeInfo, Dictionary(Of String, String))(
                    WebPartCommandIds.GetWebPartProperties, nodeInfo)
                Dim propertySource As Object = e.Node.Context.CreatePropertySourceObject(properties)
                e.PropertySources.Add(propertySource)
            End Sub
    
        End Class
    End Namespace
    
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using System.ComponentModel.Composition;
    using Microsoft.VisualStudio.SharePoint;
    using Microsoft.VisualStudio.SharePoint.Explorer;
    
    namespace ServerExplorer.SharePointConnections.WebPartNode
    {
        // Enables Visual Studio to discover and load this extension.
        [Export(typeof(IExplorerNodeTypeProvider))]
    
        // Specifies the ID for this new node type.
        [ExplorerNodeType(WebPartNodeTypeProvider.WebPartNodeTypeId)]
    
        // Defines a new node type that represents a Web Part on a SharePoint site.
        internal class WebPartNodeTypeProvider : IExplorerNodeTypeProvider
        {
            internal const string WebPartNodeTypeId = "Contoso.WebPart";
    
            public void InitializeType(IExplorerNodeTypeDefinition typeDefinition)
            {
                typeDefinition.DefaultIcon = Properties.Resources.WebPart.ToBitmap();
                typeDefinition.IsAlwaysLeaf = true;
                typeDefinition.NodePropertiesRequested += NodePropertiesRequested;
            }
    
            // Retrieves properties that are displayed in the Properties window when
            // a Web Part node is selected.
            private void NodePropertiesRequested(object sender,
                ExplorerNodePropertiesRequestedEventArgs e)
            {
                var webPartNodeInfo = e.Node.Annotations.GetValue<WebPartNodeInfo>();
    
                // Call the custom SharePoint command to get the Web Part properties.
                Dictionary<string, string> properties =
                    e.Node.Context.SharePointConnection.ExecuteCommand<
                    WebPartNodeInfo, Dictionary<string, string>>(
                    WebPartCommandIds.GetWebPartProperties, webPartNodeInfo);
    
                object propertySource = e.Node.Context.CreatePropertySourceObject(properties);
                e.PropertySources.Add(propertySource);
            }
        }
    }
    

웹 파트 데이터 클래스 정의

SharePoint 사이트의 단일 웹 파트에 대한 정보가 포함된 클래스를 정의합니다. 이 연습의 뒷부분에서는 사이트의 각 웹 파트에 대한 데이터를 검색한 다음 이 클래스 인스턴스에 할당하는 사용자 지정 SharePoint 명령을 만듭니다.

웹 파트 데이터 클래스를 정의하려면

  1. WebPartNodeExtension 프로젝트에서 WebPartNodeInfo 코드 파일을 두 번 클릭합니다.

  2. 이 파일에 다음 코드를 붙여 넣습니다.

    Imports System
    
    Namespace ServerExplorer.SharePointConnections.WebPartNode
    
        ' Contains basic data about a single Web Part on the SharePoint site. This class is 
        ' serializable so that instances of it can be sent between the WebPartNode and 
        ' WebPartCommands assemblies.
        <Serializable()> _
        Public Class WebPartNodeInfo
    
            Private siteIdValue As Guid
            Public Property SiteId As Guid
                Get
                    Return siteIdValue
                End Get
                Set(ByVal value As Guid)
                    siteIdValue = value
                End Set
            End Property
    
            Private idValue As Integer
            Public Property Id As Integer
                Get
                    Return idValue
                End Get
                Set(ByVal value As Integer)
                    idValue = value
                End Set
            End Property
    
            Private uniqueIdValue As Guid
            Public Property UniqueId As Guid
                Get
                    Return uniqueIdValue
                End Get
                Set(ByVal value As Guid)
                    uniqueIdValue = value
                End Set
            End Property
    
            Private nameValue As String
            Public Property Name As String
                Get
                    Return nameValue
                End Get
                Set(ByVal value As String)
                    nameValue = value
                End Set
            End Property
    
            Private imageUrlValue As String
            Public Property ImageUrl As String
                Get
                    Return imageUrlValue
                End Get
                Set(ByVal value As String)
                    imageUrlValue = value
                End Set
            End Property
    
        End Class
    End Namespace
    
    using System;
    
    namespace ServerExplorer.SharePointConnections.WebPartNode
    {
        // Contains basic data about a single Web Part on the SharePoint site. This class is 
        // serializable so that instances of it can be sent between the WebPartNode and 
        // WebPartCommands assemblies.
        [Serializable]
        public class WebPartNodeInfo
        {
            public Guid SiteId { get; set; }
            public int Id { get; set; }
            public Guid UniqueId { get; set; }
            public string Name { get; set; }
            public string ImageUrl { get; set; }
        }
    }
    

SharePoint 명령의 ID 정의

사용자 지정 SharePoint 명령을 식별하는 여러 문자열을 정의합니다. 이러한 명령은 이 연습의 뒷부분에서 구현합니다.

명령 ID를 정의하려면

  1. WebPartNodeExtension 프로젝트에서 WebPartCommandIds 코드 파일을 두 번 클릭합니다.

  2. 이 파일에 다음 코드를 붙여 넣습니다.

    Namespace ServerExplorer.SharePointConnections.WebPartNode
    
        Public Class WebPartCommandIds
            Public Const GetWebParts As String = "WebPart.GetWebParts"
            Public Const GetWebPartProperties As String = "WebPart.GetProperties"
        End Class
    
    End Namespace
    
    namespace ServerExplorer.SharePointConnections.WebPartNode
    {
        public static class WebPartCommandIds
        {
            public const string GetWebParts = "WebPart.GetWebParts";
            public const string GetWebPartProperties = "WebPart.GetProperties";
        }
    }
    

사용자 지정 SharePoint 명령 만들기

SharePoint 서버 개체 모델을 호출하여 SharePoint 사이트의 웹 파트에 대한 데이터를 검색하는 사용자 지정 명령을 만듭니다. 각 명령은 SharePointCommandAttribute가 적용된 메서드입니다.

SharePoint 명령을 정의하려면

  1. WebPartCommands 프로젝트에서 WebPartCommands 코드 파일을 두 번 클릭합니다.

  2. 이 파일에 다음 코드를 붙여 넣습니다.

    Imports System.Collections.Generic
    Imports Microsoft.SharePoint
    Imports Microsoft.VisualStudio.SharePoint.Commands
    
    Namespace ServerExplorer.SharePointConnections.WebPartNode
    
        Friend Class WebPartsCommands
    
            ' Gets data for each Web Part on the SharePoint site, and returns an array of 
            ' serializable objects that contain the data.
            <SharePointCommand(WebPartCommandIds.GetWebParts)> _
            Private Shared Function GetWebParts(ByVal context As ISharePointCommandContext) As WebPartNodeInfo()
    
                Dim nodeInfos = New List(Of WebPartNodeInfo)()
                Dim webParts As SPListItemCollection = context.Site.GetCatalog( _
                    SPListTemplateType.WebPartCatalog).Items
    
                For Each webPart As SPListItem In webParts
                    Dim nodeInfo As WebPartNodeInfo = New WebPartNodeInfo()
                    With nodeInfo
                        .Id = webPart.ID
                        .SiteId = webPart.ParentList.ParentWeb.ID
                        .Name = webPart.Title
                        .UniqueId = webPart.UniqueId
                        .ImageUrl = webPart.ParentList.ImageUrl
                    End With
                    nodeInfos.Add(nodeInfo)
                Next
                Return nodeInfos.ToArray()
            End Function
    
            ' Gets additional property data for a specific Web Part.
            <SharePointCommand(WebPartCommandIds.GetWebPartProperties)> _
            Private Shared Function GetWebPartProperties(ByVal context As ISharePointCommandContext, _
                ByVal webPartNodeInfo As WebPartNodeInfo) As Dictionary(Of String, String)
    
                Dim webParts As SPList = context.Site.GetCatalog(SPListTemplateType.WebPartCatalog)
                Dim webPart As SPListItem = webParts.Items(webPartNodeInfo.UniqueId)
                Return SharePointCommandServices.GetProperties(webPart)
            End Function
        End Class
    End Namespace
    
    using System.Collections.Generic;
    using Microsoft.SharePoint;
    using Microsoft.VisualStudio.SharePoint.Commands;
    
    namespace ServerExplorer.SharePointConnections.WebPartNode
    {
        internal class WebPartsCommands
        {
            // Gets data for each Web Part on the SharePoint site, and returns an array of 
            // serializable objects that contain the data.
            [SharePointCommand(WebPartCommandIds.GetWebParts)]
            private static WebPartNodeInfo[] GetWebParts(ISharePointCommandContext context)
            {
                var nodeInfos = new List<WebPartNodeInfo>();
                SPListItemCollection webParts = context.Site.GetCatalog(
                    SPListTemplateType.WebPartCatalog).Items;
    
                foreach (SPListItem webPart in webParts)
                {
                    WebPartNodeInfo nodeInfo = new WebPartNodeInfo
                    {
                        Id = webPart.ID,
                        SiteId = webPart.ParentList.ParentWeb.ID,
                        Name = webPart.Title,
                        UniqueId = webPart.UniqueId,
                        ImageUrl = webPart.ParentList.ImageUrl
                    };
                    nodeInfos.Add(nodeInfo);
                }
    
                return nodeInfos.ToArray();
            }
    
            // Gets additional property data for a specific Web Part.
            [SharePointCommand(WebPartCommandIds.GetWebPartProperties)]
            private static Dictionary<string, string> GetWebPartProperties(ISharePointCommandContext context, 
                WebPartNodeInfo nodeInfo)
            {
                SPList webParts = context.Site.GetCatalog(SPListTemplateType.WebPartCatalog);
                SPListItem webPart = webParts.Items[nodeInfo.UniqueId];
    
                return SharePointCommandServices.GetProperties(webPart);
            }
        }
    }
    

검사점

이 연습의 이전 단계를 통해 웹 파트 갤러리 노드와 SharePoint 명령을 위한 모든 코드가 프로젝트에 포함되었습니다. 솔루션을 빌드하여 두 프로젝트가 오류 없이 컴파일되는지 확인합니다.

솔루션을 빌드하려면

  • 빌드 메뉴에서 솔루션 빌드를 선택합니다.

확장을 배포하기 위한 VSIX 패키지 만들기

확장을 배포하려면 솔루션에서 VSIX 프로젝트를 사용하여 VSIX 패키지를 만듭니다. 먼저 VSIX 프로젝트에 포함된 source.extension.vsixmanifest 파일을 수정하여 VSIX 패키지를 구성합니다. 그런 다음 솔루션을 빌드하여 VSIX 패키지를 만듭니다.

VSIX 패키지를 구성하려면

  1. 솔루션 탐색기에서 WebPartNode 프로젝트의 source.extension.vsixmanifest 파일을 두 번 클릭합니다.

    Visual Studio가 매니페스트 편집기에서 파일을 엽니다. source.extension.vsixmanifest 파일은 모든 VSIX 패키지에서 필요한 extension.vsixmanifest 파일의 기초를 제공합니다. 이 파일에 대한 자세한 내용은 VSIX Extension Schema Reference를 참조하십시오.

  2. 제품 이름 상자에 Web Part Gallery Node for Server Explorer를 입력합니다.

  3. 만든 이 상자에 Contoso를 입력합니다.

  4. 설명 상자에 서버 탐색기의 SharePoint 연결 노드에 사용자 지정 웹 파트 갤러리 노드를 추가합니다. 이 확장에서는 사용자 지정 SharePoint 명령을 사용하여 서버 개체 모델을 호출합니다.라고 입력합니다.

  5. 편집기의 콘텐츠 섹션에서 콘텐츠 추가 단추를 클릭합니다.

  6. 콘텐츠 추가 대화 상자의 콘텐츠 형식 선택 목록 상자에서 MEF Component를 선택합니다.

    참고

    이 값은 extension.vsixmanifest 파일의 MefComponent 요소에 해당합니다. 이 요소는 VSIX 패키지의 확장 어셈블리 이름을 지정합니다. 자세한 내용은 MEFComponent Element (VSX Schema)를 참조하십시오.

  7. 소스 선택에서 프로젝트 라디오 단추를 클릭하고 그 옆에 있는 목록 상자에서 WebPartNodeExtension을 선택합니다.

  8. 확인을 클릭합니다.

  9. 매니페스트 편집기에서 콘텐츠 추가 단추를 다시 클릭합니다.

  10. 콘텐츠 추가 대화 상자의 콘텐츠 형식을 선택하십시오. 목록 상자에서 사용자 지정 확장 형식을 선택합니다.

    참고

    이 값은 extension.vsixmanifest 파일의 CustomExtension 요소에 해당합니다. 이 요소는 Visual Studio 확장에 포함할 사용자 지정 확장을 지정합니다. 자세한 내용은 CustomExtension Element (VSX Schema)를 참조하십시오.

  11. 형식 텍스트 상자에 SharePoint.Commands.v4를 입력합니다.

    참고

    이 값은 extension.vsixmanifest 파일에 있는 CustomExtension 요소의 Type 특성에 해당합니다. 사용자 지정 SharePoint 명령이 포함된 모든 사용자 지정 확장 어셈블리에 값 Sharepoint.Commands.v4가 필요합니다.

  12. 소스 선택에서 프로젝트 라디오 단추를 클릭하고 그 옆에 있는 목록 상자에서 WebPartCommands를 선택합니다.

  13. 확인을 클릭합니다.

  14. 빌드 메뉴에서 솔루션 빌드를 클릭합니다. 솔루션이 오류 없이 컴파일되는지 확인합니다.

  15. WebPartNode 프로젝트의 빌드 출력 폴더를 엽니다. 이제 이 폴더에 WebPartNode.vsix 파일이 들어 있습니다.

    기본적으로 빌드 출력 경로는 프로젝트 파일이 포함된 폴더 아래에 있는 .. \bin\Debug 폴더입니다.

확장 테스트

이제 서버 갤러리에서 새 웹 파트 갤러리 노드를 테스트할 준비가 되었습니다. 우선 실험 모드의 Visual Studio 인스턴스에서 확장을 디버깅합니다. 그런 다음 실험 모드의 Visual Studio 인스턴스에 새 웹 파트 노드를 사용합니다.

확장 디버깅을 시작하려면

  1. 관리자 권한으로 별도의 Visual Studio를 다시 시작하고 WebPartNode 솔루션을 엽니다.

  2. WebPartNodeExtension 프로젝트에서 SiteNodeExtension 코드 파일을 열고 NodeChildrenRequested 및 CreateWebPartNodes 메서드의 코드 첫 줄에 중단점을 추가합니다.

  3. F5 키를 눌러 디버깅을 시작합니다.

    Visual Studio에서는 확장을 %UserProfile%\AppData\Local\Microsoft\VisualStudio\10.0Exp\Extensions\Contoso\Web Part Gallery Node Extension for Server Explorer\1.0에 설치하고 실험 모드의 Visual Studio 인스턴스를 시작합니다. 이 Visual Studio 인스턴스에서 프로젝트 항목을 테스트합니다.

확장을 테스트하려면

  1. 실험 모드의 Visual Studio 인스턴스에서 보기 메뉴의 서버 탐색기를 클릭합니다.

  2. 테스트에 사용할 SharePoint 사이트가 서버 탐색기SharePoint 연결 노드 아래에 표시되는지 확인합니다. 해당 사이트가 표시되지 않으면 다음 단계를 수행합니다.

    1. SharePoint 연결을 마우스 오른쪽 단추로 클릭한 다음 연결 추가를 클릭합니다.

    2. SharePoint 연결 추가 대화 상자에서 연결할 SharePoint 사이트의 URL을 입력합니다. 개발 컴퓨터의 SharePoint 사이트를 지정하려면 https://localhost를 입력합니다.

    3. 확인을 클릭합니다.

  3. 사이트 연결 노드(사이트의 URL을 표시하는 노드)를 확장한 다음 자식 사이트 노드(예: 팀 사이트)를 확장합니다.

  4. 다른 Visual Studio 인스턴스의 코드가 이전에 NodeChildrenRequested 메서드에 설정한 중단점에서 중지하는지 확인합니다. F5 키를 눌러 프로젝트를 계속 디버깅합니다.

  5. 실험 모드의 Visual Studio 인스턴스에서 웹 파트 갤러리라는 새 노드가 최상위 사이트 노드 아래에 표시되는지 확인합니다. 웹 파트 갤러리 노드를 확장합니다.

  6. 다른 Visual Studio 인스턴스의 코드가 이전에 CreateWebPartNodes 메서드에 설정한 중단점에서 중지하는지 확인합니다. F5 키를 눌러 프로젝트를 계속 디버깅합니다.

  7. 실험 모드의 Visual Studio 인스턴스에서 연결된 사이트의 모든 웹 파트가 서버 탐색기웹 파트 갤러리 노드 아래에 표시되는지 확인합니다.

  8. 웹 파트 중 하나를 마우스 오른쪽 단추로 클릭하고 속성을 클릭합니다.

  9. 디버깅 중인 Visual Studio 인스턴스에서 웹 파트에 대한 세부 정보가 속성 창에 표시되는지 확인합니다.

Visual Studio에서 확장 제거

확장 테스트를 마친 후 Visual Studio에서 확장을 제거합니다.

확장을 제거하려면

  1. 실험 모드의 Visual Studio 인스턴스에서 도구 메뉴의 확장 관리자를 클릭합니다.

    확장 관리자 대화 상자가 열립니다.

  2. 확장 목록에서 Web Part Gallery Node Extension for Server Explorer를 선택하고 제거를 클릭합니다.

  3. 나타나는 대화 상자에서 를 클릭하여 확장을 제거합니다.

  4. 지금 다시 시작을 클릭하여 제거를 완료합니다.

  5. Visual Studio의 두 인스턴스, 즉 실험 모드의 인스턴스와 WebPartNode 솔루션이 열려 있는 Visual Studio 인스턴스를 모두 닫습니다.

참고 항목

작업

연습: 서버 탐색기 확장의 SharePoint 클라이언트 개체 모델 호출

새 비트맵 또는 다른 이미지 만들기

참조

이미지 편집기

기타 리소스

서버 탐색기에서 SharePoint 연결 노드 확장