As you stated, the .xap
file is really just a zip file masquerading under a different extension. Once you have updated the contents of the folder, simply compress the folder into a file, and then rename the file with a .xap
extension.
The following compression code can be found many places on the net with a simple google. I used the code from here and here
$folder = "C:\FolderToZip"
$zipFileName = "C:\Temp.zip"
set-content $zipFileName ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipFileName).IsReadOnly = $false
$zipFile = (new-object -com shell.application).NameSpace($zipFileName)
gci $folder | foreach-object {$zipFile.CopyHere($_.FullName); sleep -milliseconds 100}
rename-item $zipfileName "RepackagedXapFile.xap"
When I tested this, I noticed that powershell occasionally popped up the error, File not found or no read permission
. It might be some race condition, as I was able to get around it by issuing a sleep in between each copy. I know sleeps are generally frowned upon for reasons not limited to the fact that one may never know how long is long enough, but since this seems to be really for internal packaging of your test files, I don't think it's too much of a concern.