Sign in TopomorphRSS Feed

One of the chores of making a gadget is the repeated packaging of your new files to test your gadget. If you are developing a silverlight gadget this is even more true.
But you can make life easier by automating the process of packaging with a few post build actions.

In short:
- Make a new dummy project;
- Make it depend on your web project;
- Add post-build actions for the dummy project.

Though there is no way to make a post-build action in a visual studio web-project, there is a nice trick to achieve just the same. In your solution add a new (dummy) project with just one class. In your solution properties dialog set the dependency of your dummy project to the web project: 

This makes sure the "PostBuildUtilityProject"  (as it is named here) will be build after the the web project.

In the post-build actions of the dummy project I have set two lines:
The first line is a "cd" (set current working directory) command
The second line is a call to a batch file.

In the batch file there are just two lines: the first deletes the existing .gadget file, and the second line packs the necessary files into a zip file with the extension .gadget:

del SilverNewton.gadget
"C:\Program Files\7-Zip\7z" a -tzip SilverNewton.gadget @listfiles.txt

I use 7zip. Its a versatile zip program, that isn't to picky about the extension of the file name:

Besides that, it's free. You 'll find 7zip here : http://www.7-zip.org/

the syntax is simple:
"C:\Program Files\7-Zip\7z" : the path to the program
a : add files to the zip
-tzip : the type (-t) is a zip file (zip), 7 zip also handles different other types such as  tar, cab and arj (remember those?)
SilverNewton.gadget the name of the gadget 

You 'll notice that the line that does the zipping doesn't contains any files. instead it references a file "listfiles.txt". That's just a text file with each file or directory on one line. Here's mine:

Silverlight.js
settings.html
gadget.xml
gadget.html
flyout.html
icon.png
drag.png
ClientBin\*
script\*
images\*
styles\*

Why these are the files in my gadget I will explain an other post, that will give you pointers to building a gadget with silverlight

Comments