SharePoint に Business Data Connectivity (BDC) サービスのモデルを作成するには、Business Data Connectivity モデル プロジェクト項目を使用します。 既定では、このプロジェクト項目を使用してモデルを作成しただけでは、モデル内のデータがユーザーに表示されません。 ユーザーがデータを閲覧できるようにするには、それに加えて、SharePoint に外部リストを作成する必要があります。
このチュートリアルでは、ビジネス データ接続モデル プロジェクト項目の拡張機能を作成します。 開発者は、この拡張機能を使用することで、BDC モデルのデータを表示するための外部リストを同じプロジェクト内で作成できます。 このチュートリアルでは、次のタスクについて説明します。
次の 2 つの主要タスクを実行する Visual Studio の拡張機能を作成する。
BDC モデル内のデータを表示するための外部リストを生成する。 この拡張機能は、リストを定義する Elements.xml ファイルを、SharePoint プロジェクト システムのオブジェクト モデルを使用して生成します。 さらに、BDC モデルと一緒に配置できるように、このファイルをプロジェクトに追加します。
ソリューション エクスプローラー内のビジネス データ接続モデル プロジェクト項目に対するショートカット メニュー項目を追加する。 開発者は、このメニュー項目をクリックして、BDC モデル用の外部リストを生成できます。
拡張機能のアセンブリを配置するための Visual Studio Extension (VSIX) パッケージを構築する。
拡張機能をテストする。
必須コンポーネント
このチュートリアルを実行するには、開発コンピューターに次のコンポーネントが必要です。
サポート対象エディションの Microsoft Windows、SharePoint、および Visual Studio。 詳細については、「SharePoint ソリューションの開発要件」を参照してください。
Visual Studio 2010 SDK。 このチュートリアルでは、プロジェクト項目を配置するための VSIX パッケージを、SDK の VSIX プロジェクト テンプレートを使用して作成します。 詳細については、「Visual Studio の SharePoint ツールの拡張」を参照してください。
次の概念に関する知識があると役に立ちますが、チュートリアルを実行するうえで必須というわけではありません。
Microsoft SharePoint Server 2010 の BDC サービス。 詳細については、「BDC Architecture (BDC アーキテクチャ)」を参照してください。
BDC モデルの XML スキーマ。 詳細については、「BDC Model Infrastructure (BDC モデル インフラストラクチャ)」を参照してください。
プロジェクトの作成
このチュートリアルを完了するには、2 つのプロジェクトを作成する必要があります。
プロジェクト項目の拡張機能を配置するために VSIX パッケージを作成する VSIX プロジェクト。
プロジェクト項目の拡張機能を実装するクラス ライブラリ プロジェクト。
この 2 つのプロジェクトを作成することから始めます。
VSIX プロジェクトを作成するには
Visual Studio を起動します。
[ファイル] メニューの [新規作成] をポイントし、[プロジェクト] をクリックします。
[新しいプロジェクト] ダイアログ ボックスで、[Visual C#] ノードまたは [Visual Basic] ノードを展開し、[機能拡張] ノードをクリックします。
注意
[機能拡張] ノードは、Visual Studio 2010 SDK がインストールされている場合にのみ利用できます。 詳細については、冒頭の「前提条件」を参照してください。
ダイアログ ボックス上部のコンボ ボックスで、[.NET Framework 4] をクリックします。 SharePoint ツールの拡張機能を使用するには、このバージョンの .NET Framework の機能が必要です。
[VSIX プロジェクト] テンプレートをクリックします。
[プロジェクト名] ボックスに「GenerateExternalDataLists」と入力します。
[OK] をクリックします。
Visual Studio によって、GenerateExternalDataLists プロジェクトがソリューション エクスプローラーに追加されます。
拡張機能プロジェクトを作成するには
ソリューション エクスプローラーでソリューション ノードを右クリックし、[追加] をクリックして、[新しいプロジェクト] をクリックします。
注意
Visual Basic プロジェクトでソリューション エクスプローラーにソリューション ノードが表示されるのは、[全般] ([オプション] ダイアログ ボックス - [プロジェクトおよびソリューション])の [常にソリューションを表示] チェック ボックスがオンになっている場合だけです。
[新しいプロジェクト] ダイアログ ボックスで、[Visual C#] ノードまたは [Visual Basic] ノードを展開し、[Windows] をクリックします。
ダイアログ ボックス上部のコンボ ボックスで、[.NET Framework 4] を選択します。
[クラス ライブラリ] プロジェクト テンプレートを選択します。
[名前] ボックスに「BdcProjectItemExtension」と入力します。
[OK] をクリックします。
Visual Studio によって、BdcProjectItemExtension プロジェクトがソリューションに追加され、既定の Class1 コード ファイルが開きます。
Class1 コード ファイルをプロジェクトから削除します。
拡張機能プロジェクトの構成
プロジェクト項目の拡張機能を作成するためのコードを記述する前に、コード ファイルおよびアセンブリ参照を拡張プロジェクトに追加します。
プロジェクトを構成するには
BdcProjectItemExtension プロジェクトに、次の名前を持つ 2 つのコード ファイルを追加します。
ProjectItemExtension
GenerateExternalDataLists
[プロジェクト] メニューの [参照の追加] をクリックします。
[.NET] タブで、Ctrl キーを押しながら次のアセンブリをクリックし、[OK] をクリックします。
Microsoft.VisualStudio.SharePoint
System.ComponentModel.Composition
WindowsBase
プロジェクト項目の拡張機能の定義
ビジネス データ接続モデル プロジェクト項目の拡張機能を定義するクラスを作成します。 拡張機能を定義するため、このクラスに ISharePointProjectItemTypeExtension インターフェイスを実装します。 このインターフェイスは、既存の種類のプロジェクト項目を拡張する場合に必ず実装します。
プロジェクト項目の拡張機能を定義するには
ProjectItemExtension コード ファイルをダブルクリックします。
次のコードをファイルに貼り付けます。
注意
このコードを追加した直後は、いくつかのコンパイル エラーが発生します。 これらのエラーは、この後の手順でコードを追加すると解消されます。
Imports Microsoft.VisualStudio.SharePoint Imports System.ComponentModel.Composition Namespace Contoso.SharePointProjectItemExtensions.GenerateExternalDataLists ' Export attribute: Enables Visual Studio to discover and load this extension. ' SharePointProjectItemType attribute: Specifies the ID of the project item to extend. ' GenerateExternalDataListsExtension class: Defines the extension for the BDC project item. ' The other part of the partial class contains the logic for generating the external data lists. <Export(GetType(ISharePointProjectItemTypeExtension))> _ <SharePointProjectItemType("Microsoft.VisualStudio.SharePoint.BusinessDataConnectivity")> _ Partial Friend Class GenerateExternalDataListsExtension Implements ISharePointProjectItemTypeExtension ' Creates the new shortcut menu item that the user clicks to generate the external data lists. Private Sub Initialize(ByVal SharePointProjectItemType As ISharePointProjectItemType) _ Implements ISharePointProjectItemTypeExtension.Initialize AddHandler SharePointProjectItemType.ProjectItemMenuItemsRequested, AddressOf SharePointProjectItemMenuItemsRequested End Sub Private Sub SharePointProjectItemMenuItemsRequested(ByVal Sender As Object, _ ByVal e As SharePointProjectItemMenuItemsRequestedEventArgs) Dim generateListMenuItem As IMenuItem = e.ViewMenuItems.Add("Generate External Data List") AddHandler generateListMenuItem.Click, AddressOf GenerateExternalDataLists_Execute End Sub End Class End Namespace
using Microsoft.VisualStudio.SharePoint; using System.ComponentModel.Composition; namespace Contoso.SharePointProjectItemExtensions.GenerateExternalDataLists { // Enables Visual Studio to discover and load this extension. [Export(typeof(ISharePointProjectItemTypeExtension))] // Specifies the ID of the project item to extend. [SharePointProjectItemType("Microsoft.VisualStudio.SharePoint.BusinessDataConnectivity")] // Defines the extension for the BDC project item. The other part of the partial class contains // the logic for generating the external data lists. internal partial class GenerateExternalDataListsExtension : ISharePointProjectItemTypeExtension { // Implements IProjectItemTypeExtension.Initialize. Creates the new shortcut menu item that // the user clicks to generate the external data lists. public void Initialize(ISharePointProjectItemType projectItemType) { projectItemType.ProjectItemMenuItemsRequested += ProjectItemMenuItemsRequested; } private void ProjectItemMenuItemsRequested(object sender, SharePointProjectItemMenuItemsRequestedEventArgs e) { e.ViewMenuItems.Add("Generate External Data List").Click += GenerateExternalDataLists_Execute; } } }
外部データ リストの作成
BDC モデル内の各エンティティの外部データ リストを作成する GenerateExternalDataListsExtension クラスの部分定義を追加します。 外部データ リストを作成するために、このコードはまず BDC モデル ファイル内の XML データを解析して、BDC モデルのエンティティ データを読み取ります。 次に、BDC モデルに基づくリスト インスタンスを作成し、このリスト インスタンスをプロジェクトに追加します。
外部データ リストを作成するには
GenerateExternalDataLists コード ファイルをダブルクリックします。
次のコードをファイルに貼り付けます。
Imports Microsoft.VisualStudio.SharePoint Imports Microsoft.VisualBasic Imports System Imports System.Collections.Generic Imports System.IO Imports System.Linq Imports System.Text Imports System.Xml.Linq Namespace Contoso.SharePointProjectItemExtensions.GenerateExternalDataLists ' Creates the external data lists for the BDC item. The other part of the partial class ' defines the BDC project item extension. Partial Friend Class GenerateExternalDataListsExtension Private Const ModelFileNameString As String = "ModelFileName" Private Const EXTENSION_BDCM As String = ".bdcm" Private Const NamespaceString As String = "https://schemas.microsoft.com/windows/2007/BusinessDataCatalog" Private Shared ReadOnly BdcNamespace As XNamespace = XNamespace.Get(NamespaceString) ' Generates an external data list for each Entity in the BDC model. This event handler is called ' when the developer clicks the shortcut menu item that the extension adds to the BDC project item. Private Sub GenerateExternalDataLists_Execute(ByVal Sender As Object, ByVal e As MenuItemEventArgs) Dim projectItem As ISharePointProjectItem = CType(e.Owner, ISharePointProjectItem) Dim bdcmFile As ISharePointProjectItemFile = GetModelFile(projectItem) Dim doc As XDocument = XDocument.Load(bdcmFile.FullPath) Dim skippedEntities As List(Of XElement) = New List(Of XElement)() ' Try to generate an external data list for each entity defined in the BDC model file. For Each entity As XElement In doc.Root.Elements(BdcNamespace + "LobSystems").Elements( _ BdcNamespace + "LobSystem").Elements(BdcNamespace + "Entities").Elements(BdcNamespace + "Entity") If False = GenerateExternalDataList(projectItem, entity) Then skippedEntities.Add(entity) End If Next ' Report skipped entities. If skippedEntities.Count <> 0 Then Dim entityNameList As StringBuilder = Nothing skippedEntities.ForEach(Function(entity As XElement) If (entityNameList Is Nothing) Then entityNameList = New StringBuilder() Else entityNameList.AppendLine(",") End If entityNameList.Append(entity.Attribute("Name").Value) End Function) Dim message As String = String.Format("The following Entities were skipped because " & "either a LobSystemInstance, SpecificFinder, or Finder was not found for them. \r\n{0}", _ entityNameList) projectItem.Project.ProjectService.Logger.WriteLine(message, LogCategory.Warning) End If End Sub ' Gets the ISharePointProjectItemFile object for the BDC model file. Private Function GetModelFile(ByVal projectItem As ISharePointProjectItem) As ISharePointProjectItemFile Dim modelFileName As String = Nothing If projectItem.FeatureProperties.TryGetValue(ModelFileNameString, modelFileName) Then modelFileName = Path.GetFileName(modelFileName) Return (From file In projectItem.Files _ Where String.Compare(file.Name, modelFileName, StringComparison.OrdinalIgnoreCase) = 0 _ Select file).FirstOrDefault() Else ' If we can't find the ModelFileName through the FeatureProperties, ' get the first file that has a '.bdcm' extension Return (From file In projectItem.Files _ Where file.Name.EndsWith(EXTENSION_BDCM, StringComparison.OrdinalIgnoreCase) _ Select file).FirstOrDefault() End If End Function ' Boilerplate XML for the new list instance that is based on the BDC model. Private Const externalDataListContent As String = _ "<?xml version=""1.0"" encoding=""utf-8""?>" & vbCrLf & _ " <Elements https://schemas.microsoft.com/sharepoint/"">" & vbCrLf & _ " <ListInstance Title=""$EntityName$DataList""" & vbCrLf & _ " OnQuickLaunch=""TRUE""" & vbCrLf & _ " TemplateType=""104""" & vbCrLf & _ " FeatureId=""$SharePoint.Feature.Id$""" & vbCrLf & _ " Url=""Lists/$EntityName$DataList""" & vbCrLf & _ " Description=""Default List for $EntityName$."">" & vbCrLf & _ " <DataSource>" & vbCrLf & _ " <Property Name=""LobSystemInstance"" Value=""$LobSystemInstance$"" />" & vbCrLf & _ " <Property Name=""EntityNamespace"" Value=""$EntityNamespace$"" />" & vbCrLf & _ " <Property Name=""Entity"" Value=""$EntityName$"" />" & vbCrLf & _ " <Property Name=""SpecificFinder"" Value=""$SpecificFinder$"" />" & vbCrLf & _ " <Property Name=""Finder"" Value=""$Finder$"" />" & vbCrLf & _ " </DataSource>" & vbCrLf & _ " </ListInstance>" & vbCrLf & _ " </Elements>" ' Tries to generate an external data list for the specified BDC model project item and entity. Private Function GenerateExternalDataList(ByVal projectItem As ISharePointProjectItem, ByVal entity As XElement) As Boolean Dim lobSystemInstanceName As String = GetLobSystemInstanceName(entity) Dim specificFinderName As String = GetSpecificFinderName(entity) Dim finderName As String = GetFinderName(entity) Dim entityName As String = entity.Attribute("Name").Value If String.IsNullOrEmpty(lobSystemInstanceName) Or String.IsNullOrEmpty(specificFinderName) Or _ String.IsNullOrEmpty(finderName) Then Return False End If Dim newExternalDataListName As String = entityName & "DataList" Dim existingProjectItem As ISharePointProjectItem = (From existingItem As ISharePointProjectItem In projectItem.Project.ProjectItems Where existingItem.Name = newExternalDataListName Select existingItem).FirstOrDefault() ' Add a new list instance and populate it with data from the BDC model. If existingProjectItem Is Nothing Then Dim newExternalDataList As ISharePointProjectItem = projectItem.Project.ProjectItems.Add(newExternalDataListName, _ "Microsoft.VisualStudio.SharePoint.ListInstance") Dim newExternalDataListString As String = externalDataListContent newExternalDataListString = newExternalDataListString.Replace("$EntityName$", entityName) newExternalDataListString = newExternalDataListString.Replace("$LobSystemInstance$", lobSystemInstanceName) newExternalDataListString = newExternalDataListString.Replace("$EntityNamespace$", entity.Attribute("Namespace").Value) newExternalDataListString = newExternalDataListString.Replace("$SpecificFinder$", specificFinderName) newExternalDataListString = newExternalDataListString.Replace("$Finder$", finderName) Dim elementsXmlPath As String = Path.Combine(newExternalDataList.FullPath, "Elements.xml") File.WriteAllText(elementsXmlPath, newExternalDataListString) Dim elementsFile As ISharePointProjectItemFile = newExternalDataList.Files.AddFromFile(elementsXmlPath) elementsFile.DeploymentType = DeploymentType.ElementManifest End If Return True End Function Private Function GetLobSystemInstanceName(ByVal entity As XElement) As String Dim lobSystemInstances As XElement = entity.Parent.Parent.Element(BdcNamespace + "LobSystemInstances") If lobSystemInstances IsNot Nothing Then Dim lobSystemInstance As XElement = lobSystemInstances.Elements(BdcNamespace + "LobSystemInstance").FirstOrDefault() If lobSystemInstance IsNot Nothing Then Return lobSystemInstance.Attribute("Name").Value End If End If Return Nothing End Function Private Function GetSpecificFinderName(ByVal entity As XElement) As String Return GetMethodInstance(entity, "SpecificFinder") End Function Private Function GetFinderName(ByVal entity As XElement) As String Return GetMethodInstance(entity, "Finder") End Function Private Function GetMethodInstance(ByVal entity As XElement, ByVal methodInstanceType As String) As String Dim methods As XElement = entity.Element(BdcNamespace + "Methods") If methods IsNot Nothing Then For Each method As XElement In methods.Elements(BdcNamespace + "Method") Dim methodInstances As XElement = method.Element(BdcNamespace + "MethodInstances") If methodInstances IsNot Nothing Then For Each methodInstance As XElement In methodInstances.Elements(BdcNamespace + "MethodInstance") If methodInstance.Attribute("Type").Value = methodInstanceType Then Return methodInstance.Attribute("Name").Value End If Next End If Next End If Return Nothing End Function End Class End Namespace
using Microsoft.VisualStudio.SharePoint; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Xml.Linq; namespace Contoso.SharePointProjectItemExtensions.GenerateExternalDataLists { // Creates the external data lists for the BDC item. The other part of the partial class // defines the BDC project item extension. internal partial class GenerateExternalDataListsExtension { private const string ModelFileNameString = "ModelFileName"; private const string EXTENSION_BDCM = ".bdcm"; private const string NamespaceString = "https://schemas.microsoft.com/windows/2007/BusinessDataCatalog"; private static readonly XNamespace BdcNamespace = XNamespace.Get(NamespaceString); // Generates an external data list for each Entity in the BDC model. This event handler is called // when the developer clicks the shortcut menu item that the extension adds to the BDC project item. private void GenerateExternalDataLists_Execute(object sender, MenuItemEventArgs e) { ISharePointProjectItem projectItem = (ISharePointProjectItem)e.Owner; ISharePointProjectItemFile bdcmFile = GetModelFile(projectItem); XDocument doc = XDocument.Load(bdcmFile.FullPath); List<XElement> skippedEntities = new List<XElement>(); // Try to generate an external data list for each entity defined in the BDC model file. foreach (XElement entity in doc.Root.Elements(BdcNamespace + "LobSystems").Elements( BdcNamespace + "LobSystem").Elements(BdcNamespace + "Entities").Elements(BdcNamespace + "Entity")) { if (!GenerateExternalDataList(projectItem, entity)) { skippedEntities.Add(entity); } } // Report skipped entities. if (skippedEntities.Count != 0) { StringBuilder entityNameList = null; skippedEntities.ForEach(delegate(XElement entity) { if (entityNameList == null) { entityNameList = new StringBuilder(); } else { entityNameList.AppendLine(","); } entityNameList.Append(entity.Attribute("Name").Value); }); string message = string.Format("The following Entities were skipped because either a LobSystemInstance, " + "SpecificFinder, or Finder was not found for them. \r\n{0}", entityNameList); projectItem.Project.ProjectService.Logger.WriteLine(message, LogCategory.Warning); } } // Gets the ISharePointProjectItemFile object for the BDC model file. private ISharePointProjectItemFile GetModelFile(ISharePointProjectItem projectItem) { string modelFileName; if (projectItem.FeatureProperties.TryGetValue(ModelFileNameString, out modelFileName)) { modelFileName = Path.GetFileName(modelFileName); return (from file in projectItem.Files where string.Compare(file.Name, modelFileName, StringComparison.OrdinalIgnoreCase) == 0 select file).FirstOrDefault(); } else { // if we can't find the ModelFileName through the FeatureProperties, // get the first file that has a '.bdcm' extension return (from file in projectItem.Files where file.Name.EndsWith(EXTENSION_BDCM, StringComparison.OrdinalIgnoreCase) select file).FirstOrDefault(); } } // Boilerplate XML for the new list instance that is based on the BDC model. private const string externalDataListContent = @"<?xml version=""1.0"" encoding=""utf-8""?> <Elements https://schemas.microsoft.com/sharepoint/""> <ListInstance Title=""$EntityName$DataList"" OnQuickLaunch=""TRUE"" TemplateType=""104"" FeatureId=""$SharePoint.Feature.Id$"" Url=""Lists/$EntityName$DataList"" Description=""Default List for $EntityName$.""> <DataSource> <Property Name=""LobSystemInstance"" Value=""$LobSystemInstance$"" /> <Property Name=""EntityNamespace"" Value=""$EntityNamespace$"" /> <Property Name=""Entity"" Value=""$EntityName$"" /> <Property Name=""SpecificFinder"" Value=""$SpecificFinder$"" /> <Property Name=""Finder"" Value=""$Finder$"" /> </DataSource> </ListInstance> </Elements>"; // Tries to generate an external data list for the specified BDC model project item and entity. private bool GenerateExternalDataList(ISharePointProjectItem projectItem, XElement entity) { string lobSystemInstanceName = GetLobSystemInstanceName(entity); string specificFinderName = GetSpecificFinderName(entity); string finderName = GetFinderName(entity); string entityName = entity.Attribute("Name").Value; if (string.IsNullOrEmpty(lobSystemInstanceName) || string.IsNullOrEmpty(specificFinderName) || string.IsNullOrEmpty(finderName)) { return false; } string newExternalDataListName = entityName + "DataList"; ISharePointProjectItem existingProjectItem = (from ISharePointProjectItem existingItem in projectItem.Project.ProjectItems where existingItem.Name == newExternalDataListName select existingItem).FirstOrDefault(); // Add a new list instance and populate it with data from the BDC model. if (existingProjectItem == null) { ISharePointProjectItem newExternalDataList = projectItem.Project.ProjectItems.Add(newExternalDataListName, "Microsoft.VisualStudio.SharePoint.ListInstance"); string newExternalDataListString = externalDataListContent; newExternalDataListString = newExternalDataListString.Replace("$EntityName$", entityName); newExternalDataListString = newExternalDataListString.Replace("$LobSystemInstance$", lobSystemInstanceName); newExternalDataListString = newExternalDataListString.Replace("$EntityNamespace$", entity.Attribute("Namespace").Value); newExternalDataListString = newExternalDataListString.Replace("$SpecificFinder$", specificFinderName); newExternalDataListString = newExternalDataListString.Replace("$Finder$", finderName); string elementsXmlPath = Path.Combine(newExternalDataList.FullPath, "Elements.xml"); File.WriteAllText(elementsXmlPath, newExternalDataListString); ISharePointProjectItemFile elementsFile = newExternalDataList.Files.AddFromFile(elementsXmlPath); elementsFile.DeploymentType = DeploymentType.ElementManifest; } return true; } private string GetLobSystemInstanceName(XElement entity) { XElement lobSystemInstances = entity.Parent.Parent.Element(BdcNamespace + "LobSystemInstances"); if (lobSystemInstances != null) { XElement lobSystemInstance = lobSystemInstances.Elements(BdcNamespace + "LobSystemInstance").FirstOrDefault(); if (lobSystemInstance != null) { return lobSystemInstance.Attribute("Name").Value; } } return null; } private string GetSpecificFinderName(XElement entity) { return GetMethodInstance(entity, "SpecificFinder"); } private string GetFinderName(XElement entity) { return GetMethodInstance(entity, "Finder"); } private string GetMethodInstance(XElement entity, string methodInstanceType) { XElement methods = entity.Element(BdcNamespace + "Methods"); if (methods != null) { foreach (XElement method in methods.Elements(BdcNamespace + "Method")) { XElement methodInstances = method.Element(BdcNamespace + "MethodInstances"); if (methodInstances != null) { foreach (XElement methodInstance in methodInstances.Elements(BdcNamespace + "MethodInstance")) { if (methodInstance.Attribute("Type").Value == methodInstanceType) { return methodInstance.Attribute("Name").Value; } } } } } return null; } } }
チェックポイント
この段階で、プロジェクト項目の拡張機能に必要なすべてのコードがプロジェクトに揃ったことになります。 エラーが発生することなくプロジェクトをコンパイルできるかどうか、ソリューションをビルドして確認してください。
ソリューションをビルドするには
- [ビルド] メニューの [ソリューションのビルド] をクリックします。
プロジェクト項目の拡張機能を配置するための VSIX パッケージの作成
拡張機能を配置するには、ソリューションで VSIX プロジェクトを使用して VSIX パッケージを作成します。 まず、VSIX プロジェクトに含まれている source.extension.vsixmanifest ファイルを変更して、VSIX パッケージを構成します。 次に、ソリューションをビルドして VSIX パッケージを作成します。
VSIX パッケージを構成および作成するには
ソリューション エクスプローラーで、GenerateExternalDataLists プロジェクトの source.extension.vsixmanifest ファイルをダブルクリックします。
Visual Studio によってマニフェスト エディターでファイルが開きます。 source.extension.vsixmanifest ファイルが、すべての VSIX パッケージで必要とされる extension.vsixmanifest ファイルの基礎となります。 このファイルの詳細については、「VSIX Extension Schema Reference」を参照してください。
[製品名] ボックスに「External Data List Generator」と入力します。
[作成者] ボックスに「Contoso」と入力します。
[説明] ボックスに「An extension for Business Data Catalog Model project items that can be used to generate external data lists」(外部データ リストを生成する用途に使用できるビジネス データ接続モデル プロジェクト項目用の拡張機能) と入力します。
エディターの [コンテンツ] セクションで、[コンテンツの追加] をクリックします。
[コンテンツの追加] ダイアログ ボックスで、[コンテンツ タイプの選択] ボックスの一覧の [MEF コンポーネント] をクリックします。
注意
この値は、extension.vsixmanifest ファイル内の MefComponent 要素に対応します。 この要素は、VSIX パッケージ内の拡張機能アセンブリの名前を指定します。 詳細については、「MEFComponent Element (VSX Schema)」を参照してください。
[ソースの選択] の下にある [プロジェクト] をクリックし、その横のボックスの [BdcProjectItemExtension] を選択します。
[OK] をクリックします。
[ビルド] メニューの [ソリューションのビルド] をクリックします。 エラーが発生することなくプロジェクトがコンパイルされることを確認します。
GenerateExternalDataLists プロジェクトのビルド出力フォルダーを開きます。 このフォルダーに GenerateExternalDataLists.vsix ファイルが格納されていることを確認します。
既定では、プロジェクト ファイルに格納されているフォルダー の ..\bin\Debug フォルダーがビルド出力フォルダーです。
プロジェクト項目の拡張機能のテスト
これで、プロジェクト項目の拡張機能をテストする準備ができました。 まず、Visual Studio の実験用インスタンスで拡張機能プロジェクトのデバッグを開始します。 次に、Visual Studio の実験用インスタンスで拡張機能を使用して、BDC モデルの外部リストを生成します。 最後に、SharePoint サイトで外部リストを開いて正常に動作するかどうかを確認します。
拡張機能のデバッグを開始するには
管理者特権で Visual Studio を再起動し、GenerateExternalDataLists ソリューションを開きます。
BdcProjectItemExtension プロジェクトで、ProjectItemExtension コード ファイルを開き、Initialize メソッド内のコード行にブレークポイントを追加します。
GenerateExternalDataLists コード ファイルを開き、GenerateExternalDataLists_Execute メソッドのコードの先頭行にブレークポイントを追加します。
F5 キーを押してデバッグを開始します。
Visual Studio によって、拡張機能が %UserProfile%\AppData\Local\Microsoft\VisualStudio\10.0Exp\Extensions\Contoso\External Data List Generator\1.0 にインストールされ、Visual Studio の実験用インスタンスが開始されます。 このインスタンスの Visual Studio でプロジェクト項目をテストします。
拡張機能をテストするには
Visual Studio の実験用インスタンスで、[ファイル] メニューの [新規] をポイントし、[プロジェクト] をクリックします。
[Visual C#] を展開し、[SharePoint] を展開して、[2010] をクリックします。
ダイアログ ボックスの上部のコンボ ボックスで、[.NET Framework 3.5] が選択されていることを確認します。 Microsoft SharePoint Server 2010 のプロジェクトには、このバージョンの .NET Framework が必要です。
プロジェクト テンプレートの一覧の [ビジネス データ接続モデル] をクリックします。
[プロジェクト名] ボックスに「TestBDCModel」と入力します。
[OK] をクリックします。
SharePoint カスタマイズ ウィザードで、デバッグ用のサイトの URL を入力し、[完了] をクリックします。
Visual Studio のもう一方のインスタンスで、先ほど Initialize メソッドに設定したブレークポイントで、コードが停止していることを確認します。 このインスタンスの Visual Studio で F5 キーを押し、プロジェクトのデバッグを続行します。
Visual Studio の実験用インスタンスで、F5 キーを押して TestBDCModel のビルド、配置、および実行を行います。 デバッグに使用する SharePoint サイトの既定のページが Web ブラウザーに表示されます。
クイック起動領域の [リスト] セクションを見て、プロジェクトの既定の BDC モデルに基づくリストがまだ存在しないことを確認します。 まず、SharePoint のユーザー インターフェイスを使用するか、プロジェクト項目の拡張機能を使用して、外部データ リストを作成する必要があります。
Web ブラウザーを閉じます。
TestBDCModel プロジェクトが開いている方の Visual Studio のインスタンスで、ソリューション エクスプローラーの [BdcModel1] ノードを右クリックし、[外部データ リストの生成] をクリックします。
Visual Studio のもう一方のインスタンスで、先ほど GenerateExternalDataLists_Execute メソッドに設定したブレークポイントで、コードが停止していることを確認します。 F5 キーを押して、プロジェクトのデバッグを続行します。
Visual Studio の実験用インスタンスによって、TestBDCModel プロジェクトに Entity1DataList という名前のリスト インスタンスが追加されます。また、そのリスト インスタンスに対して Feature2 という名前のフィーチャーが生成されます。
F5 キーを押して TestBDCModel プロジェクトをビルド、配置、および実行します。 デバッグに使用する SharePoint サイトの既定のページが Web ブラウザーに表示されます。
クイック起動領域の [リスト] セクションに、Entity1DataList という名前のリストが含まれていることを確認します。
[Entity1DataList] リストをクリックします。
リストに Identifier1 および Message という名前の列が存在し、項目 (Identifier1 の値は 0 で、Message の値は Hello World) が 1 つ含まれていることを確認します。 このデータはすべて、ビジネス データ接続モデル プロジェクト テンプレートによって生成された既定の BDC モデルによって提供されます。
Web ブラウザーを閉じます。
開発コンピューターのクリーンアップ
プロジェクト項目の拡張機能のテストが終わったら、外部リストおよび BDC モデルを SharePoint サイトから削除し、さらにプロジェクト項目の拡張機能を Visual Studio から削除します。
SharePoint サイトから外部データ リストを削除するには
SharePoint サイトのクイック起動領域で、[Entity1DataList] リストをクリックします。
SharePoint サイトのリボンで、[リスト] タブをクリックします。
[リスト] タブで、[設定] グループの [リストの設定] をクリックします。
[権限と管理] の [このリストの削除] をクリックします。 確認のメッセージで [OK] をクリックすると、リストがごみ箱に送られます。
Web ブラウザーを閉じます。
BDC モデルを SharePoint サイトから削除するには
Visual Studio の実験用インスタンスの [ビルド] メニューで [取り消し] をクリックします。
Visual Studio によって BDC モデルが SharePoint サイトから削除されます。
プロジェクト項目の拡張機能を Visual Studio から削除するには
Visual Studio の実験用インスタンスの [ツール] メニューで、[拡張機能マネージャー] をクリックします。
[拡張機能マネージャー] ダイアログ ボックスが表示されます。
拡張機能の一覧で、[External Data List Generator] をクリックし、[アンインストール] をクリックします。
確認のダイアログ ボックスが表示されたら、[はい] をクリックして、拡張機能をアンインストールします。
[今すぐ再起動] をクリックするとアンインストールは完了です。
Visual Studio の両方のインスタンス (GenerateExternalDataLists ソリューションを開いた Visual Studio の実験用インスタンスとインスタンス) を閉じます。