カスタムの SharePoint プロジェクト項目の種類を定義する場合は、ショートカット メニュー項目にプロパティを追加できます。このメニュー項目は、ユーザーがソリューション エクスプローラーでプロジェクト項目を右クリックすると表示されます。
次の手順は、独自の SharePoint プロジェクト項目の種類が既に定義されていることを前提としています。詳細については、「方法: SharePoint プロジェクト項目の種類を定義する」を参照してください。
ショートカット メニュー項目をカスタム プロジェクト項目の種類に追加するには
ISharePointProjectItemTypeProvider 実装の InitializeType メソッドで、projectItemTypeDefinition パラメーターの ProjectItemMenuItemsRequested イベントを処理します。
ProjectItemMenuItemsRequested イベントのイベント ハンドラーで、新しい IMenuItem オブジェクトをイベント引数パラメーターの ViewMenuItems コレクションまたは AddMenuItems コレクションに追加します。
IMenuItem の新しいオブジェクトの Click のイベント ハンドラーで、userがショートカット メニュー項目を選択したときに実行するタスクを実行します。
例
コンテキスト メニュー項目をカスタムのプロジェクト項目の種類に追加する方法を次のコード例に示します。userが [ソリューション エクスプローラー] プロジェクト項目からショートカット メニューを開き、[Write Message to Output Window] のメニュー項目を選択すると、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 プロジェクト サービスを使用して、出力ウィンドウにメッセージを書き込みます。詳細については、「SharePoint プロジェクト サービスの使用」を参照してください。
コードのコンパイル
この例では、次のアセンブリへの参照を含むクラス ライブラリ プロジェクトが必要です。
Microsoft.VisualStudio.SharePoint
System.ComponentModel.Composition
プロジェクト項目の配置
自分が定義したプロジェクト項目を他の開発者が使用できるようにするには、プロジェクト テンプレートまたはプロジェクト項目テンプレートを作成します。詳細については、「SharePoint プロジェクト項目の項目テンプレートとプロジェクト テンプレートの作成」を参照してください。
プロジェクト項目を配置するには、同梱する必要のあるアセンブリやテンプレート、各種ファイルの Visual Studio 拡張機能 (VSIX) パッケージを作成します。詳細については、「Visual Studio での SharePoint ツールの拡張機能の配置」を参照してください。
参照
概念
方法: SharePoint プロジェクト項目の種類を定義する