Visual Studio 2008 SharePoint Deployment Issue

Visual Studio 2008 extensions for Sharepoint greatly ease the process of developing custom Sharepoint solutions. The extension provides a set of visual studio templates for rapid creation of Sharepoint Web Parts, Content Types, and Modules etc. You can download the extensions from this Microsoft link.

Using this extension creating and deploying a webpart is just a breeze and everything works to perfection for the first web part we create. But troubles arise when we start deploying subsequent web parts. During deployment of subsequent webparts Visual Studio 2008 comes up with the following error message.

“The feature name WebPart1 already exists in SharePoint. You need to rename the feature before solution deployment can succeed.”

This error happens even if you are given a different name for your web part file and web part class file. This is because behind the scenes Visual Studio stores the solution name as Webpart1 even if you have given a different name to your webpart. To overcome this VS 2008 behavior, the following changes have to be made to the webpart feature files.

  1. Change the name of webpart folder, webpart xml and webpart files from Webpart1 to the name of your web part for e.g. WP1. So in effect, the folder WebPart1 will become WP1, the file WebPart1.webpart will become WP1.webpart and the file WebPart1.xml will become WP1.xml.
  2. Select the Show All Files option from VS 2008 Solution Explorer toolbar.
  3. Three additional folders namely bin, obj, pkg will be displayed in grayed out style.
  4. Expand the pkg folder. Pkg folder will have a subfolder named Webpart1 and two XML files manifest.xml and solution.xml.
  5. Rename Webpart1 folder name to your webpart for e.g. WP1
  6. Edit solution.xml and change the name of feature from Webpart1 to your webpart name

<featureElement id=”c140c619-8e16-47f8-8bd0-532184591afe” name=”WP1″ />

  1. Edit manifest.xml file and change the feature manifest file location path

<FeatureManifest Location=”WP1\feature.xml” />

  1. Edit WP1/feature.xml file to change the manifest and file location
    <ElementManifest Location=”WP1\WP1.xml”/>

<ElementFile Location=”WP1\WP1.webpart” />

After performing the above changes the web part deployment will happen successfully. A simpler method to avoid all this trouble is as follows

  1. Immediately after creating a new webpart project, remove the Webpart1 folder completely.
  2. Add the new web part to the project by right-clicking on the project and selecting the new item from the context menu.
  3. In the Add new item dialog box select Sharepoint from categories and Select Web Part from templates.
  4. Give a name for your webpart and click Add button.