Question

I am writing some automation code, and I am adding dll files into a xap file. I extract the xap (I treat it like a zip), add in the dlls and change the appmanifest.xml.

However I can't seem to change the folder back into a silverlight xap file. This is the only option since the developers will not add testing hooks into their programs.

In powershell, how do I convert directory type? Property: Type File folder --> XAP (file)

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top