Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Posted Thursday, July 15, 2010 4:34 PM by CoreyRoth

That’s a mouth full.  I always suspected it was possible to use Visual Studio 2010 to package up my SharePoint web parts and other artifacts into a solution (.wsp file) and turn around and deploy that code into MOSS 2007.  Today I gave it a try and it actually works pretty well.  This post will show you how to do it.  I will remind you that you won’t be able to take advantage of any of the automatic deployment, debugging features built into Visual Studio 2010 and SharePoint 2010, but you will have a nice solution file that was built automatically without having to use a third party tool like WSPBuilder.  You can then take the solution package and deploy it to SharePoint with stsadm.

I will start off by using the SharePoint 2010 Empty Project Template.  Now, unfortunately, the wizard that starts this project has a dependency on SharePoint 2010.  It simply won’t run without it.  However, if you happen to already have a copy of a project that has been created, you can open an existing SharePoint 2010 project template on a computer that does not have SharePoint installed.  I have attached a copy of my Visual Studio solution for you to use as a starting point if you need it. 

Once I have my project open, I proceed to create a web part as shown below in the Solution Explorer.

VSS2010Wss3WebPartSolutionExplorer

I don’t have to make any modifications to the class.  So I add some simple “Hello, World!” code to it.

VSS2010Wss3WebPartCode

We’re targeting SharePoint version 3, so that means we need to change some references.  All of the DLLs in SharePoint 2010 are version 14.  We need version 12 DLLs.  So what you will need to do is go get a copy of Microsoft.SharePoint.dll (and possibly Microsoft.SharePoint.Security.dll) from your version 3 SharePoint farm.  We then need to remove the reference to the version 14 DLLs.  Click on Microsoft.SharePoint.dll and Microsoft.SharePoint.Security.dll and remove them from the solution.  We then add our version 12 DLLs to the references list and we’re ready to compile our web part for WSS3. 

VSS2010Wss3WebPartReferences VSS2010Wss3WebPartReferencesProperties

At this point, I will remind you of the caveats of perusing this completely unsupported approach.  Obviously, you can’t need to make sure you are only using API calls from version 3.  Using a class from SharePoint 2010 is obviously not going to work.

Build your project and it should compile successfully.  Now, I figured everything would work at this point but I discovered one thing that I had to change in this process.  The SharePoint 2010 solution schema has a new attribute called SharePoint version on the SharePoint element.  WSS3 does not like this.

VSS2010Wss3WebPartManifest

Luckily, I discovered, that if we delete the value from the property window, it actually removes the attribute.

VSS2010Wss3WebPartManifestProperties

Simply, remove the value there and we are ready to package the project.

VSS2010Wss3WebPartPackage

When this is complete, you can browse the file system and find your .wsp file in the bin folder.  Copy the .wsp file to the SharePoint 2007 server if you aren’t already on it.  Then add and deploy the package with stsadm.  At this point, you will have a feature that you can activate on your SharePoint 2007 server.  Go to site collection features and activate it.

VSS2010Wss3WebPartCodeFeatureActivated

The web part should now be in the Solution Gallery.  Now edit a page, and add a new web part.  Your web part should be in the group labeled Custom assuming you haven’t changed it.

VSS2010Wss3WebPartAdd

We can now verify that the web part code works on the page.

VSS2010Wss3WebPartComplete

As you can see it’s really pretty easy to build a WSS3 web part in Visual Studio 2010 and deploy it.  We lose some of the cool VS2010/SP2010 integration features of course, but the fact it builds the package for us is a huge win.  Not to mention, upgrading our code to work in SharePoint 2010 later will be pretty easy since all we have to do is change our references from the version 12 to the version 14 DLLs.  I’ve only covered how to do a web part here today.  I suspect other SharePoint Project Items will work as well.  I’ll try them out soon and let you know how they work.  As a reminder, I have attached a copy of my solution to this post for you to use in case you don’t have SharePoint 2010 installed any where.  Give it a try and let me know if it works for you.

Comments

# Twitter Trackbacks for Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007 - Corey Roth - DotNetMafia.com - Tip of the Day [dotnetmafia.com] on Topsy.com

Pingback from  Twitter Trackbacks for                 Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007 - Corey Roth - DotNetMafia.com - Tip of the Day         [dotnetmafia.com]        on Topsy.com

# re: Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Monday, July 19, 2010 1:28 AM by Fran

Thank you, this is a very good tip!

# re: Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Monday, July 19, 2010 2:17 AM by Ahmed Eldesokey ( Egypt)

Really it was a nice article attractive , I will try it .

any way thnx alot amn

# Using Visual Studio 2010 SharePoint Templates to deploy a web part … | Learn Visual Studio

Pingback from  Using Visual Studio 2010 SharePoint Templates to deploy a web part … | Learn Visual Studio

# Deploy SharePoint 2010 Solution « Microsoft Technology, .Net, BizTalk, Sharepoint & etc.

Pingback from  Deploy SharePoint 2010 Solution « Microsoft Technology, .Net, BizTalk, Sharepoint & etc.

# re: Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Wednesday, October 6, 2010 5:08 PM by Paul Sorauer

Hi Corey

I think there may be a problem with the project you attached. The package.package as well as the feature seems to be basically an empty schema, so I don't get the SharePoint version attribute and other things.

Thus the feature is empty and when deploying to the server the feature does not appear as per your screenshot above.

Can you please re-post the attachment? I don't have SP 2010 on my dev box which is one reason this was such a good post!

Thanks,

Paul.

# re: Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Thursday, October 14, 2010 2:18 AM by Madhavan

I followed the steps. Its working fine. Great. Thanks.

# re: Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Tuesday, November 2, 2010 9:51 AM by d4_david

Hi,

I am real beginner at SharePoint developing, so I am sorry for this post but I need to solve it.

I don´t understand this part of instructions :

"When this is complete, you can browse the file system and find your .wsp file in the bin folder.  Copy the .wsp file to the SharePoint 2007 server if you aren’t already on it.  Then add and deploy the package with stsadm.  At this point, you will have a feature that you can activate on your SharePoint 2007 server.  Go to site collection features and activate it."

I really would appreciate if somebody will write me an explanation or just send a link where it has been already explained.

Thank you a lot

d4_david@centrum.cz

# re: Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Friday, November 5, 2010 11:01 AM by CoreyRoth

@d4_david The wsp file in the bin folder contains your code in a single deployable package.

See the bottom of this post for instructions on how to deploy the .wsp with stsadm.

www.dotnetmafia.com/.../intro-to-sharepoint-development-how-to-build-and-deploy-a-web-part.aspx

# re: Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Wednesday, December 8, 2010 10:53 AM by Tesfaye

It is really a nice article. Corey I have one question. I couldnt see any place where to delete the value of the Sharepoint 2010 from the property window so that it can delete from the attribute. The problem is I dont see any schema like that. Please help

# re: Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Tuesday, March 15, 2011 5:55 AM by Tomas Breen

Hi Corey,

Thanks for the sample solution. It builds fine, but when I try and package the project, I get "Package Failed". There are no other errors apart from  "Error: Object reference not set to an instance of an object.

========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========" in the output window.

Any idea why this might happen? I have made no adjustments to the downloaded solution.

Regards,

Tomas

# re: Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Tuesday, March 22, 2011 11:32 PM by CoreyRoth

@Tomas I have seen this when there are issues with what is going into the solution package.  Double check all of your features.  You may need to exclude items from your project and add them back one at a time to get the package to work.

# Downgrade a SharePoint 2010 Visual Web Part to SharePoint 2007 | E. Struyf 's Blog

Pingback from  Downgrade a SharePoint 2010 Visual Web Part to SharePoint 2007 | E. Struyf 's Blog

# re: Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Thursday, December 22, 2011 8:06 AM by Shashank Sharma

This is one of the best articles so far I have read online. No crap, just useful information. Very well presented. Its really helpful for beginner as well as developer. Thanks for sharing with us. Check out this link too its also assist in understanding of sharepoint.

mindstick.com/.../9e1d1fe1-7e51-4d01-86ec-f1f679631a7e

# re: Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Wednesday, January 18, 2012 11:50 AM by SPbb

Works for me! THANKS!

This maybe late. I used Sharepoint Designer 2007 for our WSS3.0 site costumizing webparts and planning to build webpart using VS2010 any tips/tutorial out there how do I start?

Using this template can I start building webparts?

Any help would be very much appreciated!

# re: Using Visual Studio 2010 SharePoint Templates to deploy a web part in SharePoint 2007

Tuesday, February 7, 2012 12:10 AM by CoreyRoth

@SPBB There really isn't a good transition strategy to go from one to the other.  However, see this post for help on getting started building a web part.

www.dotnetmafia.com/.../intro-to-sharepoint-2010-development-how-to-build-and-deploy-a-web-part.aspx

Leave a Comment

(required) 
(required) 
(optional)
(required)