Walkthrough: Extending a SharePoint Project Item Type
You can use the Business Data Connectivity Model project item to create a model for the Business Data Connectivity (BDC) service in SharePoint. By default, when you create a model by using this project item, the data in the model is not displayed to users. You must also create an external list in SharePoint to enable users to view the data.
In this walkthrough, you will create an extension for the Business Data Connectivity Model project item. Developers can use the extension to create an external list in their project that displays the data in the BDC model. This walkthrough demonstrates the following tasks:
Creating a Visual Studio extension that performs two main tasks:
It generates an external list that displays the data in a BDC model. The extension uses the object model for the SharePoint project system to generate an Elements.xml file that defines the list. It also adds the file to the project so that it is deployed together with the BDC model.
It adds a shortcut menu item to the Business Data Connectivity Model project items in Solution Explorer. Developers can click this menu item to generate an external list for the BDC model.
Building a Visual Studio Extension (VSIX) package to deploy the extension assembly.
Testing the extension.
Prerequisites
You need the following components on the development computer to complete this walkthrough:
Supported editions of Microsoft Windows, SharePoint and Visual Studio. For more information, see Requirements for Developing SharePoint Solutions.
The Visual Studio SDK. This walkthrough uses the VSIX Project template in the SDK to create a VSIX package to deploy the project item. For more information, see Extending the SharePoint Tools in Visual Studio.
Knowledge of the following concepts is helpful, but not required, to complete the walkthrough:
The BDC service in Microsoft SharePoint Server 2010. For more information, see BDC Architecture.
The XML schema for BDC models. For more information, see BDC Model Infrastructure.
Creating the Projects
To complete this walkthrough, you need to create two projects:
A VSIX project to create the VSIX package to deploy the project item extension.
A class library project that implements the project item extension.
Start the walkthrough by creating the projects.
To create the VSIX project
Start Visual Studio.
On the menu bar, choose File, New, Project.
In the New Project dialog box, expand the Visual C# or Visual Basic nodes, and then choose the Extensibility node.
Note
The Extensibility node is available only if you install the Visual Studio SDK. For more information, see the prerequisites section earlier in this topic.
In the list at the top of the New Project dialog box, choose .NET Framework 4.5.
SharePoint tools extensions require features in this version of the .NET Framework.
Choose the VSIX Project template.
In the Name box, enter GenerateExternalDataLists, and then choose the OK button.
Visual Studio adds the GenerateExternalDataLists project to Solution Explorer.
If the source.extension.vsixmanifest file doesn’t open automatically, open its shortcut menu in the GenerateExternalDataLists project, and then choose Open
Verify that the source.extension.vsixmanifest file has a non-blank entry (enter Contoso) for the Author field, save the file, and then close it.
To create the extension project
In Solution Explorer, open the shortcut menu for the GenerateExternalDataLists solution node, choose Add, and then choose New Project.
Note
In Visual Basic projects, the solution node appears in Solution Explorer only when the Always show solution check box is selected in the General, Projects and Solutions, Options Dialog Box.
In the Add New Project dialog box, expand the Visual C# or Visual Basic nodes, and then choose the Windows node.
In the list at the top of the dialog box, choose .NET Framework 4.5.
In the list of project templates, choose Class Library.
In the Name box, enter BdcProjectItemExtension, and then choose the OK button.
Visual Studio adds the BdcProjectItemExtension project to the solution and opens the default Class1 code file.
Delete the Class1 code file from the project.
Configuring the Extension Project
Before you write code to create the project item extension, add code files and assembly references to the extension project.
To configure the project
In the BdcProjectItemExtension project, add two code files that have the following names:
ProjectItemExtension
GenerateExternalDataLists
Choose the BdcProjectItemExtension project, and then, on the menu bar, choose Project, Add Reference.
Under the Assemblies node, choose the Framework node, and the select the check box for each of the following assemblies:
System.ComponentModel.Composition
WindowsBase
Under the Assemblies node, choose the Extensions node, and then select the check box for the following assembly:
- Microsoft.VisualStudio.SharePoint
Choose the OK button.
Defining the Project Item Extension
Create a class that defines the extension for the Business Data Connectivity Model project item. To define the extension, the class implements the ISharePointProjectItemTypeExtension interface. Implement this interface whenever you want to extend an existing type of project item.
To define the project item extension
Paste the following code into the the ProjectItemExtension code file.
Note
After you add this code, the project will have some compile errors. These errors will go away when you add code in later steps.
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; } } }
Creating the External Data Lists
Add a partial definition of the GenerateExternalDataListsExtension class that creates an external data list for each entity in the BDC model. To create the external data list, this code first reads the entity data in the BDC model by parsing the XML data in the BDC model file. Then, it creates a list instance that is based on the BDC model and adds this list instance to the project.
To create the external data lists
Paste the following code into the GenerateExternalDataLists code file.
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; } } }
Checkpoint
At this point in the walkthrough, all the code for the project item extension is now in the project. Build the solution to make sure that the project compiles without errors.
To build the solution
- On the menu bar, choose Build, Build Solution.
Creating a VSIX Package to Deploy the Project Item Extension
To deploy the extension, use the VSIX project in your solution to create a VSIX package. First, configure the VSIX package by modifying the source.extension.vsixmanifest file that is included in the VSIX project. Then, create the VSIX package by building the solution.
To configure and create the VSIX package
In Solution Explorer, open the shortcut menu for the source.extension.vsixmanifest file in the GenerateExternalDataLists project, and then choose Open.
Visual Studio opens the file in the manifest editor. The source.extension.vsixmanifest file is the basis for the extension.vsixmanifest file is required by all VSIX packages. For more information about this file, see VSX Schema for Extensions.
In the Product Name box, enter External Data List Generator.
In the Author box, enter Contoso.
In the Description box, enter An extension for Business Data Connectivity Model project items that can be used to generate external data lists.
On the Assets tab of the editor, choose the New button.
The Add New Asset dialog box appears.
In the Type list, choose Microsoft.VisualStudio.MefComponent.
Note
This value corresponds to the MefComponent element in the extension.vsixmanifest file. This element specifies the name of an extension assembly in the VSIX package. For more information, see MEFComponent Element.
In the Source list, choose A project in current solution.
In the Project list, choose BdcProjectItemExtension, and then choose the OK button.
On the menu bar, choose Build, Build Solution.
Make sure that the project compiles and builds without errors.
Make sure that the build output folder for the GenerateExternalDataLists project now contains the GenerateExternalDataLists.vsix file.
By default, the build output folder is the ..\bin\Debug folder under the folder that contains your project file.
Testing the Project Item Extension
You are now ready to test the project item extension. First, start debugging the extension project in the experimental instance of Visual Studio. Then, use the extension in the experimental instance of Visual Studio to generate an external list for a BDC model. Finally, open the external list on the SharePoint site to verify that it works as expected.
To start debugging the extension
If necessary, restart Visual Studio with administrative credentials, and then open the GenerateExternalDataLists solution.
In the BdcProjectItemExtension project, open the ProjectItemExtension code file, and then add a breakpoint to the line of code in the Initialize method.
Open the GenerateExternalDataLists code file, and then add a breakpoint to the first line of code in the GenerateExternalDataLists_Execute method.
Start debugging by choosing the F5 key or, on the menu bar, choosing Debug, Start Debugging.
Visual Studio installs the extension to %UserProfile%\AppData\Local\Microsoft\VisualStudio\10.0Exp\Extensions\Contoso\External Data List Generator\1.0 and starts an experimental instance of Visual Studio. You will test the project item in this instance of Visual Studio.
To test the extension
In the experimental instance of Visual Studio, on the menu bar, choose File, New, Project.
In the New Project dialog box, expand the Templates node, expand the Visual C# node, expand the SharePoint node, and then choose 2010.
In the list at the top of the dialog box, make sure that .NET Framework 3.5 is selected. Projects for Microsoft SharePoint Server 2010 require this version of the .NET Framework.
In the list of project templates, choose SharePoint 2010 Project.
In the Name box, enter SharePointProjectTestBDC, and then choose the OK button.
In the SharePoint Customization Wizard, enter the URL of the site that you want to use for debugging, choose Deploy as a farm solution, and then choose the Finishbutton.
Open the shortcut menu for the SharePointProjectTestBDC project, choose Add, and then choose New Item.
In the Add NewItem – SharePointProjectTestBDC dialog box, expand the installed language node, expand the SharePoint node.
Choose the 2010 node, and then choose the Business Data Connectivity Model (Farm Solution only) template.
In the Name box, enter TestBDCModel, and then choose the Add button.
Verify that the code in the other instance of Visual Studio stops on the breakpoint that you set in the Initialize method of the ProjectItemExtension code file.
In the stopped instance of Visual Studio, choose the F5 key, or on menu bar, choose Debug, Continue to continue to debug the project.
In the experimental instance of Visual Studio, choose the F5 key, or, on the menu bar, choose Debug, Start Debugging to build, deploy, and run the TestBDCModel project.
The web browser opens to the default page of the SharePoint site that's specified for debugging.
Verify that the Lists section in the Quick Launch area doesn't yet contain a list that's based on the default BDC model in the project. You must first create an external data list, either by using the SharePoint user interface or by using the project item extension.
Close the web browser.
In the instance of Visual Studio that has the TestBDCModel project open, open the shortcut menu for the TestBDCModel node in Solution Explorer, and then choose Generate External Data List.
Verify that the code in the other instance of Visual Studio stops on the breakpoint that you set in the GenerateExternalDataLists_Execute method. Choose the F5 key, or, on the menu bar, choose Debug, Continue to continue to debug the project.
The experimental instance of Visual Studio adds a list instance that's named Entity1DataList to the TestBDCModel project, and the instance also generates a feature that's named Feature2 for the list instance.
Choose the F5 key, or, on the menu bar, choose Debug, Start Debugging to build, deploy, and run the TestBDCModel project.
The web browser opens to the default page of the SharePoint site that's used for debugging.
In the Lists section of the Quick Launch area, choose the Entity1DataList list.
Verify that the list contains columns that are named Identifier1 and Message, in addition to one item that has an Identifier1 value of 0 and a Message value of Hello World.
The Business Data Connectivity Model project template generates the default BDC model that provides all of this data.
Close the web browser.
Cleaning up the Development Computer
After you finish testing the project item extension, remove the external list and BDC model from the SharePoint site and remove the project item extension from Visual Studio.
To remove the external data list from the SharePoint site
In the Quick Launch area of the SharePoint site, choose the Entity1DataList list.
In the Ribbon on the SharePoint site, choose the List tab.
On the List tab, in the Settings group, choose List Settings.
Under Permissions and Management, choose Delete this list, and then choose OK to confirm that you want to send the list to the Recycle Bin.
Close the web browser.
To remove the BDC model from the SharePoint site
In the experimental instance of Visual Studio, on the menu bar, choose Build, Retract.
Visual Studio removes the BDC model from the SharePoint site.
To remove the project item extension from Visual Studio
In the experimental instance of Visual Studio, on the menu bar, choose Tools, Extensions and Updates.
The Extensions and Updates dialog box opens.
In the list of extensions, choose External Data List Generator, and then choose the Uninstall button.
In the dialog box that appears, choose Yes to confirm that you want to uninstall the extension.
Choose Restart Now to complete the uninstallation.
Close both instances of Visual Studio (the experimental instance and the instance in which the GenerateExternalDataLists solution is open).
See Also
Concepts
Extending the SharePoint Project System