Walkthrough: Deploying a Project Task List Definition
This walkthrough shows you how to use Visual Studio 2012 to create, customize, debug, and deploy a SharePoint list to track project tasks.
This walkthrough illustrates the following tasks:
Creating a SharePoint project with a list that contains tasks.
Adding the list to a SharePoint feature.
Adding an event receiver to the list.
Creating and customizing a SharePoint package to deploy your feature..
Building, testing, and deploying your SharePoint solution.
Note
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.
Prerequisites
You need the following components to complete this walkthrough:
Supported editions of Microsoft Windows and SharePoint. For more information, see Requirements for Developing SharePoint Solutions.
Visual Studio Professional or an edition of Visual Studio Application Lifecycle Management (ALM).
Creating a SharePoint List
Create a SharePoint list project and associate the list definition with tasks.
To create a SharePoint list project
Open the New Project dialog box, expand the SharePoint node, and then choose the 2010 node.
In the Templates pane, choose the SharePoint 2010 Project template, name the project ProjectTaskList, and then choose the OK button.
The SharePoint Customization Wizard appears.
Specify the local SharePoint site that you use for debugging, choose the Deploy as a farm solution option button, and then choose the Finish button.
Open the shortcut menu for the project, and then choose Add, New Item.
In the Templates pane, choose the List template, and then choose the Add button.
The SharePoint Customization Wizard appears.
In the What name do you want to display for your list? box, enter Project Task List.
Choose the Create a non-customizable list based on an existing list type of option button, and then, in its list, choose Tasks, and then choose the Finish button.
The list, feature, and package appear in Solution Explorer.
Adding an Event Receiver
In the task list, you can add an event receiver that automatically sets the due date and description of the task. The following procedure adds a simple event handler to the list instance as an event receiver.
To add an event receiver
Open the shortcut menu for the project node, choose Add, and then choose New Item.
In the list of SharePoint templates, choose the Event Receiver template, and then name it ProjectTaskListEventReceiver.
The SharePoint Customization Wizard appears.
On the Choose Event Receiver Settings page, choose List Item Events as the event receiver type in the What type of event receiver do you want list.
In the What item should be the event source list, choose Tasks.
In the list of events to handle, select the check box next to An item was added, and then choose the Finish button.
A new event receiver node is added to the project with a code file that is named ProjectTaskListEventReceiver.
Add code to the ItemAdded method in the ProjectTaskListEventReceiver code file. Each time a new task is added, a default due date and a description is added to the task. The default due date is July 1, 2009.
Public Overrides Sub ItemAdded(ByVal properties As SPItemEventProperties) MyBase.ItemAdded(properties) Dim web As SPWeb = properties.OpenWeb() properties.ListItem("Due Date") = "July 1, 2009" properties.ListItem("Description") = "This is a critical task." properties.ListItem.Update() End Sub
public override void ItemAdded(SPItemEventProperties properties) { base.ItemAdded(properties); SPWeb web = properties.OpenWeb(); properties.ListItem["Due Date"] = "July 1, 2009"; properties.ListItem["Description"] = "This is a critical task."; properties.ListItem.Update(); }
Customizing the Project Task List Feature
When you create a SharePoint solution, Visual Studio automatically creates features for the default project items. You can customize the project task list settings for the SharePoint site by using the Feature Designer.
To customize the project task list feature
In Solution Explorer, expand Features.
Open the shortcut menu for Feature1, and then choose View Designer.
In the Title box, enter Project Task List Feature.
In the Scope list, choose Web.
In the Properties window, enter 1.0.0.0 as the value for the Version property.
Customizing the Project Task List Package
When you create a SharePoint project, Visual Studio automatically adds the features that contain the default project items to the package. You can customize the project task list settings for the SharePoint site by using the Package Designer.
To customize the project task list package
In SolutionExplorer, open the shortcut menu for Package, and then choose View Designer.
In the Name box, enter ProjectTaskListPackage.
Select the Reset Web Server check box.
Building and Testing the Project Task List
When you run the project, the SharePoint site opens. However, you must manually navigate to the location of the task list.
To test the project task list
Choose the F5 key to build and deploy your project task list.
The SharePoint site opens.
Choose the Home tab.
In the left sidebar, choose the Project Task List link.
The Project Task List page appears.
In the List Tools tab, choose the Items tab.
In the Items group, choose the New Item button.
In the Title text box, enter Task1.
Choose the Save button.
After the site is refreshed, the Task1 task appears with a due date of 7/1/2009.
Choose Task1.
The detailed view of the task appears, and the description shows "This is a critical task."
Deploying the Project Task List
After you build and test the project task list, you can deploy it to the local system or a remote system. The local system is the same computer on which you developed the solution, whereas a remote system is a different computer.
To deploy the project task list to the local system
On the Visual Studio menu bar, choose Build, Deploy Solution.
Visual Studio recycles the IIS application pool, retracts any existing versions of the solution, copies the solution package (.wsp) file to SharePoint, and then activates its features. You can now use the solution in SharePoint. For more information about deployment configuration steps, see How to: Edit a SharePoint Deployment Configuration.
To deploy the project task list to a remote system
On the Visual Studio menu bar, choose Build, Publish.
In the Publish dialog box, choose the Publish to File System option button.
You can change the target location in the Publish dialog box by choosing the ellipsis button and then navigating to another location.
Choose the Publish button.
A .wsp file is created for the solution.
Copy the .wsp file to the remote SharePoint system.
Use the PowerShell Add-SPUserSolution command to install the package on the remote SharePoint installation. (For farm solutions, use the Add-SPSolution command.)
For example, Add-SPUserSolution C:\MyProjects\ProjectTaskList\ProjectTaskList\bin\Debug\ProjectTaskList.wsp.
Use the PowerShell Install-SPUserSolution command to deploy the solution. (For farm solutions, use the Install-SPSolution command.)
For example, Install-SPUserSolution –Identity ProjectTaskList.wsp –Site http://NewSiteName.
For more information about remote deployment, see Using Solutions and Adding and Deploying Solutions with PowerShell in SharePoint 2010.
Next Steps
You can learn more about how to customize and deploy SharePoint solutions from the following topics: