11 Sep 2011

Windows SharePoint Services Solution Package .WSP

A Solution Package is a cabinet file (.cab compressed file) with an extension of .wsp—which stands for Windows SharePoint Services Solution Package—provided to automate the process of installing features and customizations.

A .wsp contains a solution-specific manifest file, called solution manifest, it is a XML file

<Solution
Description = "Text"
DeploymentServerType = "ApplicationServer" | "WebFrontEnd"
ResetWebServer = "TRUE" | "FALSE"
ResetWebServerModeOnUpgrade = "Recycle" | "StartStop"
SharePointProductVersion = "Text"
SolutionId = "Text"
Title = "Text" >
<ActivationDependencies />
<ApplicationResourceFiles />
<Assemblies />
<CodeAccessSecurity />
<DwpFiles />
<FeatureManifests />
<Resources />
<SiteDefinitionManifests />
<RootFiles />
<TemplateFiles />
</Solution>

 

STSADM.EXE command line to deploy:

Installing a solution

STSADM.EXE –o addsolution –filename filepath.wsp

Deploy

STSADM.EXE -o deploysolution
-name <Solution name>
[-url <virtual server url>]
[-allcontenturls]
[-time <time to deploy at>]
[-immediate]
[-local]
[-allowgacdeployment]
[-allowcaspolicies]
[-lcid <language>]
[-force]

 

Windows PowerShell script

Add-SPSolution file.wsp

Install-SPSolution –Identity file.wsp –GACDeployment –AllWebApplications

 

 

You can schedule the deployment at night

A sandboxed solution is a .wsp package deployed at the Site Collection level

Within Visual Studio 2010, you can choose to manage the project deployment through the Package Explorer and the Package Designer.

At the bottom of the package Explorer, there are three tabs (Design, Advanced, and Manifest)

A feature activation dependency gives you the ability to define a sequence of deployment for features

You can also create custom resource files and you can add feature event receivers

Deployment with Visual Studio 2010  will automatically retract the old version and release the new one, deactivating the feature before retraction and activating it again during deployment.

 

Upgrading Solutions and Features

 

Update-SPSolution -Identity file.wsp -LiteralPath c:\file_v2.wsp –GACDeployment

 

SharePoint will update the .wsp package stored in the configuration database and will synchronize every server in the farm with the content of the new package.

With SharePoint 2010, the feature’s manifest has a section in which you can declare upgrade actions to execute during the Upgrade process

If you need to execute some custom code during the upgrade process, you can configure the CustomUpgradeAction

 

The new features’ manifest schema supports declaration of version ranges via the VersionRange element

A feature manifest that supports versioning with different upgrade paths for different versions.

<UpgradeActions>
<VersionRange BeginVersion="0.0.0.0" EndVersion="1.5.0.0">
<MapFile FromPath="Old.aspx" ToPath="New.aspx" />
</VersionRange>
<VersionRange BeginVersion="1.5.0.0" EndVersion="2.0.0.0">
<MapFile FromPath="New.aspx" ToPath="Latest.aspx" />
</VersionRange>
</UpgradeActions>

Feature Receivers

A feature receiver is a class that executes some custom code upon the occurrence of specific lifecycle-related events

Feature Activation Occurs when a feature has been activated
Feature Deactivating Occurs while a feature is deactivating
Feature Installation Occurs when a feature has been installed
Feature Uninstalling Occurs while a feature is uninstalling
Feature Upgrading Occurs while a feature is upgrading

 

public abstract class SPFeatureReceiver {
public SPFeatureReceiver();
public virtual void FeatureActivated(SPFeatureReceiverProperties properties);
public virtual void FeatureDeactivating(SPFeatureReceiverProperties properties);
public virtual void FeatureInstalled(SPFeatureReceiverProperties properties);
public virtual void FeatureUninstalling(SPFeatureReceiverProperties properties);
public virtual void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, IDictionary<string, string> parameters);
}

public sealed class SPFeatureReceiverProperties : IDisposable {
public SPFeatureDefinition Definition { get; internal set; }
public SPFeature Feature { get; }
public SPSite UserCodeSite { get; }
}

You should access the context of your feature through the Feature.Parent property,

The Parent property could be the whole farm (SPFarm), a single web application (SPWebApplication), a Site Collection (SPSite), or a single website (SPWeb). It is up to you to know the target scope of your feature

To create a feature receiver, you need to implement the receiver class, build its assembly, put it into the GAC, and declare the ReceiverAssembly and ReceiverClass attributes in a feature manifest XML file.

 

FeatureUpgrading Events

This is a new event, introduced in SharePoint 2010 for the purpose of handling features’ upgrades.

The feature manifest file with the configuration of the custom upgrade action.

<UpgradeActions>
<CustomUpgradeAction Name="UpgradeSampleList">
<Parameters>
<Parameter Name="ShowOnQuickLaunch">False</Parameter>
<Parameter Name="EnableContentTypes">True</Parameter>
</Parameters>
</CustomUpgradeAction>
</UpgradeActions>

 

public virtual void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, IDictionary<string, string> parameters);

The method invocation receives the Name attribute of the CustomUpgradeAction inside the upgradeActionName argument, and the set of Parameter elements through the parameters dictionary.

No comments:

Post a Comment