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 put CabLib.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 folder testing\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 file Update-<your template>.wsp
will be created with content from "extracted" folder