How to modify a WSP file (convert .cab to .wsp)
-
11-12-2020 - |
Question
I want to do some modifications to a site template, mainly to set its master page , same as mentioned here link
so i did the following stpes:-
- i save a site as template.
- i went to "Site Settings">>"Solutions".
- i download the .wsp file representing the site template.
- i rename the .wsp to .cab
- using a tool named ACDZip i open the .cab , edit the .xml file.
- save the file inside the .cab
now i am not sure how i can convert the .cab to .wsp file again? so i can upload my .wsp site template again inside the solutions ?? i tried rename the .cab to .wsp but seems this steps will modify the name not the extension !!
Solution
You can (also) use Visual Studio to Import and modify your WSP.
Have a look at this link from Microsoft (For 2010 but still working for 2013): Importing the .wsp File
in few step :
- Create a VS project from type : Import SharePoint Solution Package
- Choose your WSP (after it will create the SharePoint project with all files/elements of you wsp
- make your change is the solution
- Package and Deploy your new solution
OTHER TIPS
You can do that from PowerShell. For that purpose you need small but extremely helpful library called 'CabLib'. It's included as part of the wspbuilder (old tool to build and pack projects for SharePoint 2007).
You need to download CabLib.dll
from here - WSPBuilder Extensions 1.0.6. Under the downloads select "CabLib.dll for x64 systems (version: 10.5)"
Now follow this steps:
- Create a folder, say
testing
, in that folder putCabLib.dll
and your.wsp
file. - Create new PowerShell script in that folder, called say
pack.ps1
. - Put following inside your
pack.ps1
:
$currentDir = Split-Path -Path $MyInvocation.MyCommand.Path -Parent
# LOAD CABLIB LIBRARY TO EXTRACT/COMPRESS .WSP FILES
[void][reflection.assembly]::LoadFile("$currentDir\CabLib.dll")
function Extract-Directory ( $cabFileFullPathAndFilename, $dir){
$c = new-object CabLib.Extract
$c.ExtractFile($cabFileFullPathAndFilename, $dir)
}
function Compress-Directory ($dir, $cabFileFullPathAndFilename){
write $dir
$c = new-object CabLib.Compress
$c.CompressFolder($dir, $cabFileFullPathAndFilename, $null, $null, $null, 0)
}
function DoWork($action) {
$file = "<your wsp template name>.wsp"
$file = Get-ChildItem $file
$fileDir = $file.Directory
$fileName = $file.Name
$tempFolder = "$currentdir\extracted"
$newFile = "$fileDir\Updated-$fileName"
if($action -eq "extract") {
Write-Host "Extracting...."
Extract-Directory $file $tempFolder
return;
}
if($action -eq "compress") {
Write-Host "Compressing...."
if((Test-Path $newFile) -ne $True) { New-Item $newFile -type file | Out-Null }
Compress-Directory $tempFolder $newFile
Write-Host "Cleaning Up...."
Remove-Item $tempFolder -recurse
return;
}
}
DoWork($args[0])
- Inside script update
$file
variable to point to your actual.wsp
. - Open Powershell in your newly created folder
testing
. - Run
.\pack.ps1 "extract"
. New foldertesting\extracted
will be created with content of your.wsp
. - Inside this folder perform required updates to xml files, etc.
- From Powershell run
.\pack.ps1 "compress"
. Folder will deleted and new fileUpdate-<your template>.wsp
will be created with content from "extracted" folder