Exercise 3: Deploying and Debugging SPT Projects
Now it's time to test your work and see how your project behaves when tested inside a SharePoint site collection.
- Start your work by inspecting and configuring the VS 2010 SPT project deployment options.
- Right-click on the ContosoWebParts project node in the Solution Explorer and click Properties.
- Navigate to the SharePoint tab to see the project deployment options.
- Note that there are two text boxes that allow you to add command-line instructions which will execute either just before and directly after the SPT deploy steps are processed. You are not going to add anything to either of the two top text boxes.
- Find the combo box control with the caption Active Deployment Configuration and change the selected item from Default to No Activation.
- Inside the Edit Configurations list box, select the No Activation configuration and click the View… button to inspect its deployment configuration steps.
Click OK to close the View Deployment Configuration dialog. Save all your work and close the page which shows the project properties.
Figure 1
The View Deployment Configuration dialog
Now it's time to run the Deploy command. First, make sure the Output Window is visible so you can see how the things progress during the execution of the Deploy command (Note: to show the Output Window select the Visual Studio View menu » Output). Then right-click on the ContosoWebParts project in Solution Explorer and run the project Deploy command.
Figure 2
Deploy the web part from within Visual Studio 2010. C# Shown, VB.NET similar for Deploy.
- Examine the Output Window after the Deploy command has completed. Verify the steps that provided output to the Output windows.
- At this point, the solution package for the ContosoWebParts project has been deployed on the local SharePoint farm. Let's test out your work by trying to activate the feature you defined inside the ContosoWebParts project.
- In browser, navigate to the test site at https://intranet.contoso.com/sites/lab02.
- Click Site Actions » Site Settings to navigate to the SiteSettings page.
- Inside the Site Collection Administration section of the Site Settings page, click on the Site collection features link to navigate to the Site Collection Administration > Features page.
Locate the feature you have been working on with a title of Custom Web Parts. You should also be able to see the feature's custom feature icon.
Figure 3
The site collection features page
Activate the Custom Web Parts feature. If you return to the site's home page you should be able to verify that the code inside the FeatureActivated event handler executed and changed the site's title and its site icon.
Figure 4
The changed title on the Home page
Now, navigate back to the Site Collection Features page. Deactivate the Contoso Web Parts feature so that you can test the code in the FeatureDeactivating event handler. Return to the site's home page and verify that the site title has been restored to its original value and that the site icon has been changed back to the default site icon for SharePoint sites.
Figure 5
After the deactivation of the feature, the original title is visible on the Home page
- Now it's time to practice entering debug mode so that you can single step through the code while it's executing inside the context of the test site.
Open the source file Main.EventReceiver.cs and add a breakpoint to FeatureActivated.
Figure 6 C#
Place a breakpoint in the C# code of the FeatureActivated event
Figure 17 VB.NET
Place a breakpoint in the VB.NET code of the FeatureActivated event
- Start the project in debug mode by running Debug » Start Debugging menu command or pressing the equivalent shortcut key which is [F5]. (Note: if you receive the Debugging Not Enabled dialog box, make certain to select the Modify the Web.config file to enable debugging option button and click OK.)
- After running the Start Debugging command wait until the Visual Studio debugger has launched Internet Explorer and navigated to the test site.
Within the test site, navigate to the (Site Actions » Site Settings ) Site Collection Administration > Site collection features page and activate the Custom Web Parts feature. At this point you should fall into the Visual Studio debugger and break at the line where you set of the breakpoint. If you do not fall into the Visual Studio debugger when you first activate the feature, try to deactivate and reactivate the feature.
Figure 7 C#
Hitting the C# breakpoint
Figure 8 VB.NET
Hitting the VB.NET breakpoint
- Press the [F11] key to single-step through the remaining lines of code. You should be able to hit [F11] repeatedly until the Visual Studio debugger relinquishes control back to the Internet Explorer.
- Return to Visual Studio and stop the debugger by running the Debug » Stop Debugging menu command or by pressing the equivalent shortcut key which is [Shift]+[F5].
- Remove the breakpoint from your code.
In this exercise you deployed and tested your custom SPT project as well as saw the native debugging experience.