Sunday, November 2, 2008

Another one on repacking XAPs to reduce filesize

I've seen quite some articles on repacking your XAP file to reduce the filesize. You can do this manually by using archiving utilities like 7-ZIP, WINRar or the Windows built in zip support.

Delay did a great article on this which inspired me to do the following:

I created a very small application called ReXapper.exe which can do exactly the same as Delay describes but there is no external archiving utility necessary. It uses the SharpZipLib to re-zip the file. So there's just a tiny (124 kb) command-line executable.

The executable requires .NET framework 2.0. It has only 1 parameter: -xap for the xap file.

To automatically re-xap your project after building follow these steps:
1. Copy the executable to a folder. I used d:\tools\rexapper\
2. Open you project in Visual Studio. Go to the properties of the project (using the Project menu) and locate the "Post-build event command line" box.
3. Paste the following in the box:
D:\tools\ReXapper\ReXapper.exe -xap "$(TargetDir)$(TargetName).xap"




Now build your project. In the Output window you will see the ReXapper.exe is called and it will output the following three things:
- filesize before ReXapping
- filesize after ReXapping
- time spent on ReXapping



As you will see it is pretty fast so don't worry about it slowing you down.

If you want to use ReXapper.exe, you can download it here:

ReXapper

If you want the source to make some changes or additions, drop me a message.

Hope this helps.

10 comments:

  1. Thanks for this, my Silverlight 2 XAP goes from 1.6meg to 1.2meg. I was performing this process by hand previously so this is a real time saver.

    ReplyDelete
  2. Very cool, I'll definitely use this. I don't get why it's even necessary, though -- why wouldn't VS be using the highest compression settings during publishing anyway?

    ReplyDelete
  3. Good job!

    old size: 1271740, new size: 883382

    ReplyDelete
  4. It works great. And it is fast

    ReplyDelete
  5. Very nice, thank you!

    ReplyDelete
  6. I study in the computer department in the last year

    I want you to need ideas for the project finals (Graduation Project)

    So that ideas for building Web sites

    Please help me

    ReplyDelete
  7. The download link seems not to work now?

    ReplyDelete
  8. Nice new building. Pooltable, Wii and fireplace. It looks like the Google HQ :)

    ReplyDelete
  9. Awesome tool man, thanks a lot

    ReplyDelete