다음을 통해 공유


방법: 사용자 지정 SharePoint 프로젝트 항목 형식에 바로 가기 메뉴 항목 추가

사용자 지정 SharePoint 프로젝트 항목 형식을 정의하는 경우 프로젝트 항목에 바로 가기 메뉴 항목을 추가할 수 있습니다. 메뉴 항목은 솔루션 탐색기에서 해당 프로젝트 항목을 사용자가 마우스 오른쪽 단추로 클릭하면 나타납니다.

다음 단계에서는 사용자 고유의 SharePoint 프로젝트 항목 형식이 이미 정의되어 있는 것으로 가정합니다. 자세한 내용은 방법: SharePoint 프로젝트 항목 형식 정의를 참조하십시오.

사용자 지정 프로젝트 항목 형식에 바로 가기 메뉴 항목을 추가하려면

  1. ISharePointProjectItemTypeProvider 구현의 InitializeType 메서드에서 projectItemTypeDefinition 매개 변수의 ProjectItemMenuItemsRequested 이벤트를 처리합니다.

  2. ProjectItemMenuItemsRequested 이벤트의 이벤트 처리기에서 새 IMenuItem 개체를 이벤트 인수 매개 변수의 ViewMenuItems 또는 AddMenuItems 컬렉션에 추가합니다.

  3. 사용자가 바로 가기 메뉴 항목을 클릭하면 실행되도록 할 작업을 새 IMenuItem 개체의 Click 이벤트 처리기에서 수행합니다.

예제

다음 코드 예제에서는 상황에 맞는 메뉴 항목을 사용자 지정 프로젝트 항목 형식에 추가하는 방법을 보여 줍니다. 사용자가 솔루션 탐색기에서 프로젝트 항목을 마우스 오른쪽 단추로 클릭하고 출력 창에 메시지 쓰기 메뉴 항목을 클릭하면 Visual Studio에서는 출력 창에 메시지를 표시합니다.

Imports System
Imports System.ComponentModel.Composition
Imports Microsoft.VisualStudio.SharePoint

Namespace Contoso.Examples.ProjectItemTypeWithMenu

    <Export(GetType(ISharePointProjectItemTypeProvider))> _
    <SharePointProjectItemType("Contoso.ExampleProjectItemType")> _
    <SharePointProjectItemIcon("ExampleProjectItemType.ProjectItemIcon.ico")> _
    Friend Class ExampleProjectItemTypeWithMenu
        Implements ISharePointProjectItemTypeProvider

        Private Sub InitializeType(ByVal projectItemTypeDefinition As ISharePointProjectItemTypeDefinition) _
            Implements ISharePointProjectItemTypeProvider.InitializeType
            projectItemTypeDefinition.Name = "ExampleProjectItemType"
            projectItemTypeDefinition.SupportedDeploymentScopes = _
                SupportedDeploymentScopes.Site Or SupportedDeploymentScopes.Web
            projectItemTypeDefinition.SupportedTrustLevels = SupportedTrustLevels.All

            AddHandler projectItemTypeDefinition.ProjectItemMenuItemsRequested, AddressOf ProjectItemMenuItemsRequested
        End Sub

        Private Sub ProjectItemMenuItemsRequested(ByVal Sender As Object,
            ByVal e As SharePointProjectItemMenuItemsRequestedEventArgs)
            Dim menuItem As IMenuItem = e.ViewMenuItems.Add("Write Message to Output Window")
            AddHandler menuItem.Click, AddressOf MenuItem_Click
        End Sub

        Private Sub MenuItem_Click(ByVal Sender As Object, ByVal e As MenuItemEventArgs)
            Dim projectItem As ISharePointProjectItem = CType(e.Owner, ISharePointProjectItem)
            projectItem.Project.ProjectService.Logger.WriteLine(
                String.Format("This message was written from a shortcut menu for {0}.", projectItem.Name),
                LogCategory.Status)
        End Sub
    End Class
End Namespace
using System;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.SharePoint;

namespace Contoso.Examples.ProjectItemTypeWithMenu
{
    [Export(typeof(ISharePointProjectItemTypeProvider))]
    [SharePointProjectItemType("Contoso.ExampleProjectItemType")]
    [SharePointProjectItemIcon("ExampleProjectItemType.ProjectItemIcon.ico")]
    internal class ExampleProjectItemTypeWithMenu : ISharePointProjectItemTypeProvider
    {
        public void InitializeType(ISharePointProjectItemTypeDefinition projectItemTypeDefinition)
        {
            projectItemTypeDefinition.Name = "ExampleProjectItemType";
            projectItemTypeDefinition.SupportedDeploymentScopes =
                SupportedDeploymentScopes.Site | SupportedDeploymentScopes.Web;
            projectItemTypeDefinition.SupportedTrustLevels = SupportedTrustLevels.All;

            projectItemTypeDefinition.ProjectItemMenuItemsRequested += 
                projectItemTypeDefinition_ProjectItemMenuItemsRequested;
        }

        void projectItemTypeDefinition_ProjectItemMenuItemsRequested(object sender,
            SharePointProjectItemMenuItemsRequestedEventArgs e)
        {
            IMenuItem menuItem = e.ViewMenuItems.Add("Write Message to Output Window");
            menuItem.Click += MenuItemExtension_Click;
        }

        void MenuItemExtension_Click(object sender, MenuItemEventArgs e)
        {
            ISharePointProjectItem projectItem = (ISharePointProjectItem)e.Owner;
            projectItem.Project.ProjectService.Logger.WriteLine(
                String.Format("This message was written from a shortcut menu for {0}.", projectItem.Name),
                LogCategory.Status);
        }
    }
}

이 예제에서는 SharePoint 프로젝트 서비스를 사용하여 출력t 창에 메시지를 작성합니다. 자세한 내용은 SharePoint 프로젝트 서비스 사용을 참조하십시오.

코드 컴파일

이 예제에는 다음 어셈블리에 대한 참조가 있는 클래스 라이브러리 프로젝트가 필요합니다.

  • Microsoft.VisualStudio.SharePoint

  • System.ComponentModel.Composition

프로젝트 항목 배포

다른 개발자가 프로젝트 항목을 사용할 수 있도록 하려면 프로젝트 템플릿이나 프로젝트 항목 템플릿을 만듭니다. 자세한 내용은 SharePoint 프로젝트 항목에 대한 항목 템플릿 및 프로젝트 템플릿 만들기를 참조하십시오.

프로젝트 항목을 배포하려면 어셈블리, 템플릿 및 프로젝트 항목과 함께 배포할 다른 모든 파일에 대한 VSIX(Visual Studio Extension) 패키지를 만듭니다. 자세한 내용은 Visual Studio에서 SharePoint 도구에 대한 확장 배포를 참조하십시오.

참고 항목

작업

방법: SharePoint 프로젝트 항목 형식 정의

기타 리소스

방법: 사용자 지정 SharePoint 프로젝트 항목 형식에 속성 추가

사용자 지정 SharePoint 프로젝트 항목 형식 정의