Mar 10, 2009

Create a SharePoint Solution

SharePoint use solution file to deploy solution. There are some tools to create a solution file automatically, like stsdev. But it still important to understand how the solution deployment works

MakeCab does not care about the how to deploy the solution. The job of Makecab.exe is to package all the source file and a ddf file. Sharepoint solution engine take care about of installation and deployment based on the ddf file and the manifest.xml file

The first job is to create a cab file. To create a cab file, makecab.exe need to use the ddf file. the ddf file tells makecab what files need to be packages and how they are organized in the package(what subfolder to hold a file). Below is an exmaple that are generated by the stsdev utility.

; Generated by STSDEV at 3/11/2009 12:26:53 AM .OPTION EXPLICIT .Set CabinetNameTemplate=FirstFeature.wsp .set DiskDirectoryTemplate=CDROM .Set CompressionType=MSZIP .Set UniqueFiles=off .Set Cabinet=on .Set DiskDirectory1=DeploymentFiles ;*** Solution manifest DeploymentFiles\manifest.xml ;*** Assembly files bin/debug/FirstFeature.dll ;*** add files for FirstFeature feature .Set DestinationDir=FirstFeature RootFiles\TEMPLATE\FEATURES\FirstFeature\elements.xml RootFiles\TEMPLATE\FEATURES\FirstFeature\feature.xml ;*** add files for FirstFeature\css feature .Set DestinationDir=FirstFeature\css RootFiles\TEMPLATE\FEATURES\FirstFeature\css\mystyle.css ;*********************************** ;*** Begin TemplateFiles section *** ;*********************************** .Set DestinationDir=IMAGES\FirstFeature RootFiles\TEMPLATE\IMAGES\FirstFeature\AfricanPith32.gif

Now we have all the files package the wsp file. Solution Deployment is accomplished in two step, installation and deployment. Installation is to add the package to central admin storage. Deployment is to physically deploy the files to a web server and install the feature to the web server. During installation, the engine will check the manifest.xml and feature_name\feature.xml file to check if all the files required are included in the package. If yes, the installation will succeed. If not, the installation will abort. During deployment, the engine will also use the manifest.xml and feature.xml to copy the files to front end server. It is possible that the package has some files that feature required. In that case, those are just ignored, the engine only copy those files that are shown in manifest.xml and feature.xml. To copy files, the engine does not care about the Module nodes in the element manifest files, it cares about in feature.xml, the and in the manifest. If you file that your wsp file has included the content files, but they are not copied to the front end server, you need to make sure they are shown those nodes.

To install a solution, we can use command line.

"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe" -o addsolution -filename DeploymentFiles\FirstFeature.wsp "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe" -o execadmsvcjobs

To deploy a soltuion, we can use command line,

"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe" -o deploysolution -name FirstFeature.wsp -immediate -allowgacdeployment "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe" -o execadmsvcjobs

To undeploy a solution,

"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe" -o retractsolution -name FirstFeature.wsp -immediate

To uninstall a solution,

"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe" -o deletesolution -name FirstFeature.wsp

To upgrade a solution,

"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe" -o upgradesolution -name FirstFeature.wsp -filename DeploymentFiles\FirstFeature.wsp -local -allowgacdeployment

This upgrade only update the configuration database, if the solution has been deployed to front end server, the solution need to be redeployed again to the front end server.

In development, we don't really need to use solution deployment, only need to copy the feature file and other content files to folder 12, and install the feature again.

xcopy /e /y "RootFiles\*" "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12" stsadm.exe -o installfeature {-filename | -name } [-force]