Sunday, June 28, 2009

Extending STSADM...Develop your own commands : Part 2

In part 1, we have discussed how to extend STSADM using Visual Basic. We have developed our FramManifest command which we use to output the SharePoint farm content hierarchy into an XML file.

We have deployed our new command manually, which is not the way we deploy things in SharePoint. The best way is to build a SharePoint solution file (WSP), then deploy it to the farm.

A SharePoint solution is a cab file with a .wsp extension that tells SharePoint how to install this solution and how to use it.

There are two ways to build a SharePoint solution file :

- The automated way, using tools available on the web such as Wspbuilder or STSDEV or VSeWSS.

- The other way is to do the whole thing yourself. This is the best way if you want to understand how solutions files are built, and that's what we are going to do for our Farm Manifest STSADM extension project.

There are four steps to manually create and deploy a SharePoint solution file :

To begin, here is how our project looks in the solution explorer :

The project as you have noticed, contains two folders : "Config" whose content will be copied to the "/Config" folder of the 12 hive, and the folder "Solution" where the generated solution file will go.

Step 1 : Create the manifest.xml file

The manifest.xml contains a unique ID for the solution and the files this solution will deploy :
<?xml version="1.0" encoding="utf-8" ?>
<Solution
SolutionId="2D7B9843-6285-4e67-B393-CB210278E976"
xmlns="http://schemas.microsoft.com/sharepoint/">

<Assemblies>
<Assembly Location="MyStsadmCommands.dll" DeploymentTarget="GlobalAssemblyCache" />
</Assemblies>

<RootFiles>
<RootFile Location="Config\stsadmcommands.MyStsadmCommands.xml" />
<RootFile Location="MyStsadmCommands.dll" />
</RootFiles>

</Solution>

Step 2 : Create the the DDF (Diamond Directive File)

The .ddf file is used with the makecab.exe tool to build the .wsp file
OPTION EXPLICIT
.Set CabinetNameTemplate=MyStsadmCommands.wsp
.Set DiskDirectory1=Solution
.Set Cabinet=on
.Set MaxDiskSize=0
.Set CompressionType=MSZIP;
.Set DiskDirectoryTemplate=CDROM;

manifest.xml manifest.xml

CONFIG\stsadmcommands.MyStsadmCommands.xml config\stsadmcommands.MyStsadmCommands.xml

bin\Debug\MyStsadmCommands.dll MyStsadmCommands.dll


Step 3 : Build the solution file (wsp)

I usually use a command file "MakeSolution.cmd" to build the solution :
@echo off
makecab.exe /f Cab.ddf

The execution of this command file is done in the post build events of the project :


Now that every thing is ready, right-click on the project name in the solution explorer window then click "Build" or just press CTRL+SHIF+B. the "MyStsadmCommands.wsp" file should be by now created in the "/Solution" folder of the project.

Step 4 : Deploy the solution

To deploy the solution, we have to first add it to the solutions store by using the command :

Stsadm -o AddSolution -filename c:\vsprojects\Mystsadmcommands\solution\MyStsadmCommands.wsp 'Or whatever is the path of your solution file.

Then we have to deploy the solution to the farm :

Stsadm -o DeploySolution -name
MyStsadmCommands.wsp -immediate -AllowGacDeployment

To verify that the solution is really deployed and can be used, go to "Central Administration > Operations > Solution Management". You should see it in the solutions list as shown below :



That's it. Hope this helps.

No comments:

Post a Comment