In the first exercise, you will create an empty project and focus on the aspects of the Visual Studio 2010 SharePoint Tools that are common across all projects created with this toolset. Most of your work will involve changing the properties of the project and properties of the project's main feature.
If you haven’t already done so, run the batch file named SetupLab02.bat, found in the c:\Student\Labs\02_VS2010_SPT\ folder, to create the new site collection that will be used to test and debug the code you will be writing in this lab. This batch file creates a new site collection at an URL of http://intranet.contoso.com/sites/Lab02.
Launch the Internet Explorer and navigate to the top-level site at http://intranet.contoso.com/sites/Lab02. You should observe that the newly-created site is a Blank site. This is the site you will use to test and debug the project you will develop throughout this entire lab exercise.
Now launch Microsoft Visual Studio 2010 with administrator privileges by right-clicking on its Start menu shortcut and clicking the Run as Administrator option. Starting Visual Studio in this manner (i.e. with administrative permissions) makes Visual Studio debugger work correctly when attaching to the SharePoint worker process.
Launch Visual Studio 2010
Create a new Visual Studio project named ContosoWebParts based on the SharePoint Tools project of type Empty Project. You can find this project type using the path Visual C#/Visual Basic » SharePoint » 2010. Ensure the .NET Framework 3.5 is selected instead of the default .NET Framework 4.0. Also, remove the check from the Create directory for solution checkbox. Failure to do so will result in a namespace of ContosoWebParts.ContosoWebParts being generated (instead of ContosoWebParts) which may cause issues later in this lab.
Create an empty SharePoint project
Click OK to start the SharePoint Customization Wizard.
When the SharePoint Customization Wizard prompts you for a local debugging site, enter the URL of http://intranet.contoso.com/sites/Lab02. Change the trust level to Deploy as a farm solution and then click Finish.
The SharePoint Customization Wizard
In the Solution Configurations drop-down box, located near the center of the toolbar, select Configuration Manager…
The target platform must be set to x64 or Any CPU
On the Configuration Manager dialog box, in the Active solution platform drop-down box note that for SharePoint Project types the default platform is Any CPU. Close the Configuration Manager window.
Once the new project has been created, you should be able to observe it has several nodes, two of which are Features and Package. The Features node and the Package node are unique to projects created with the Visual Studio 2010 SharePoint Tools.
The Solution Explorer C#/VB.NET
Right-click the Features node and choose Add Feature. A feature with the name Feature1 is added. Right-click on this node and click Rename. Rename this feature to Main.
Add a new feature to the project. C# shown/VB.NET Similar in Features area
Double-click the Main feature to open the feature in the feature designer. Use the feature designer to change the feature’s Title and Description using the following values:
Title: Custom Web Parts
Description: My very first project using the Visual Studio 2010 Tools
You must also change the Scope setting of the Main feature from the default value of Web to a value of Site.
Don't be confused here. Remember a Scope setting of Web results in site-level activation of the feature while a Scope setting of Site results in activation at the site collection level. The change of the feature's Scope setting to Site is required due to the fact that Web Parts deployment requires a feature which activates at site collection scope in order to properly deploy Web Part description files.
The Feature Designer. C# shown, VB.NET similar in Main.Feature properties area
Now you are going to add a few graphic images into your project so they are deployed inside the SharePoint Images folder. The first step to doing this correctly is to add a mapped folder to your project for the SharePoint Images folder. Accomplish this by right-clicking the ContosoWebParts project in the Solution Explorer, expanding the Add menu and selecting the SharePoint "Images" Mapped Folder command.
Add the SharePoint Images mapped folder. C# shown, VB.NET similar.
After completing the previous step you should be able to see that there is an Images directory inside your project. You should also be able to observe that there is a child folder inside the Images folder with the same name as the project ContosoWebParts.
This demonstrates how the SPT helps to ensure best practices with SharePoint development. When adding image files to your project, do not add them directly inside the Images folder. Instead, add them to the inner directory in this case named ContosoWebParts to avoid file name conflicts with the image files that Microsoft deploys inside the Images directory.
There are three GIF files inside the folder C:\Student\Labs\02_VS2010_SPT\StarterFiles. These files are named FeatureIcon.gif and SiteIcon.gif, WebPartIcon.gif. Right-click on the ContosoWebParts folder inside the Images folder and select the Add » Existing Items... command. When the resulting dialog opens, navigate to the folder location that contains the GIF files. Add all three GIF files to the project.
Add a number of images to the Images mapped folder. C# shown, VB.NET similar Images folder.
The first GIF file that you will put to use is the FeatureIcon.gif by modifying the ImageUrl property of the Main feature.
a.Open the Main feature in the feature designer and make sure it is the active window. (Note: if necessary, double click on the Main feature in the Solution Explorer to open the designer. Now click in the Main.Feature window to activate it).
b.Find the property sheet for the Main feature (on the lower right side of the screen)
c.Update the Image Url property with an URL that is relative to the Images which should be ContosoWebParts\FeatureIcon.gif.
Change the Image Url property of the feature
Save all the work you have done to the Main feature.
In this exercise you created your first feature using the SPT tools and added a mapped folder to the project. In future exercises you’ll add additional pieces to the project to make it more useful.