SharePoint 2007 Web Part Deployment Tutorial
There are a bunch of tutorials out there that use C# to create a class library and the put that in the GAC (Windows assemblies folder) etc. I could not get those to work for the life of me. The best way I have found to develop, test, and then deploy a custom SharePoint Web Part to the production server is with Visual Studio SharePoint Extensions, for VS 2005 or VS 2008. Except it seems you can only install this if you have Windows SharePoint Services 3.0 installed. And you can only install WSS 3.0 on Windows Server 2003 SP1. Sorry, no free download for that.
First you will need a test server, with Windows Server 2003 SP1. Install WSS 3.0. Just do what it says, run the configuration afterwards. The user that is currently logged on will have administrator control over the new SharePoint team site so you shouldn’t have to mess with any of the SharePoint settings. You might want to add at least one other user permissions to the test Sharepoint site incase you get locked out. Now install Visual Studio, either flavor. Then install the SharePoint extensions for the installed Visual Studio. Reboot.
Now you are ready to make a Web Part. When you open up VS you should see a SharePoint section under C#. Hey, there is a Web Part template! Score! So select the Web Part template, name the project something uselful, like “PoopOnAStick”. Conveniently, they even have a “hello world” code commented out for us. Uncomment it and hit F5 or the green play button up top.
Building…Deploying…Deploy Succeeded!
Navigate the browser to the local sharepoint, should be http://localhost/ and once logged in go to Site Actions -> Site Settings. Under Galleries, click on Web Parts. We should see our new Web Part1. You can click on it for a demo of it. To add it, go back to the main page, click on Site Actions -> Edit Page. Click on an Add Web Part button, find our WebPart1, check it and hit OK. It should now be apart of the SharePoint site. All we have to do now is get it to the production website. Its actually not too bad.
In the Visual Studio Projects directory, go the folder containing our Web Part. Keep going into folders until you find the Debug folder in the “bin” directory. Inside this folder are all the goodies: setup.bat, our dll’s and .wsp files. You can zip this folder up and bring it over to the production server. While you transfer the files, bit by bit, open up setup.bat in notepad and get familiar with it. We are going to be editing this file to match the deployment servers settings. Make note of all the paths and urls: SPLocation, DefaultWebUrl, DefaultSiteUrl, etc.
Edit the setup.bat to match the production server shouldn’t be to hard. I basically looked over all the path variables and followed them on the test server and made sure they matched on the production server. And they did. If not, look around for them and find them. Hopefully someone knows where they installed Sharepoint if its not in the default location, which I believe mine were. The only thing I had to change was the site url. From http://localhost to http://servername:port because we had a few sharepoint sites on the same server. If you don’t suppply the correct port, it won’t know where to install it. Once that is edited, run it and it should be deployed! Yay. If not. Use your mad debuggin skills to figure out what the errors are in the setup.bat file. Oh, and if you need to delete it, follow the SPFeaturesLocation path in the setup.bat and you should see a folder of your Web Part. Delete the folder in that directory. Here is my LInitialize section of my setup.bat. Really, the only part I changed.
@rem---------------------------------------------------------------------- @rem LInitialize @rem---------------------------------------------------------------------- :LInitialize set SPLocation=%CommonProgramFiles%\Microsoft Shared\web server extensions\12 set SPAdminTool=%SPLocation%\BIN\stsadm.exe set Install= set Uninstall= set PackageFile=%~dp0SamWebPart.wsp set PackageName=SamWebPart.wsp set DefaultWebUrl=http://sharepoint-server:8080/ set DefaultSiteUrl=http://sharepoint-server:8080/ set TargetWebUrl= set TargetSiteUrl= set SPTemplateLocation=%SPLocation%\template set SPFeaturesLocation=%SPTemplateLocation%\features set SPSiteTemplateLocation=%SPTemplateLocation%\sitetemplates set ValidationFailed=goto LParseArgs
Tags: c#, sharepoint, web parts