Thursday, 16 January 2014

Create SharePoint WSP (Cab) file using powerShell

After downloading Site solution file, I have done some modification be changing the .wsp to .cab file and extracted all the files in a folder.
After modification, I tried to restore as wsp file. It started throwing error.
After googling I found this excellent link showing that how we can create wsp file from file/folder using PowerShell

$destWSPfilename = "<Path where you want to save wsp file>\<filename.wsp>"
$sourceSolutionDir = [System.IO.DirectoryInfo]"<Source from where you are retrieving file>"
$a = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$ctor = $a.GetType("Microsoft.SharePoint.Utilities.Cab.CabinetInfo").GetConstructors("Instance, NonPublic")[0]

$cabInf = $ctor.Invoke($destWSPfilename );

$mi = $cabInf.GetType().GetMethods("NonPublic, Instance, DeclaredOnly")
$mi2 = $null
foreach( $m in $mi ) {
    if( $m.Name -eq "CompressDirectory" -and $m.GetParameters().Length -eq 4 ) {
        $mi2 = $m;

$mi2.Invoke($cabInf, @( $sourceSolutionDir.FullName, $true, -1,$null ));   

1 comment :

  1. when i create .wsp package using above script, i got error at the time of deployment manifest.xml missing.