Developing Vista Sidebar Gadget with Script#

C# to JavaScript compiler? What? Jea! I thought the same way. It’s amazing what smart people can invent. My men is Nikhil Kothari with his Script#. What do I need the C# to JavaScript compiler for, you ask. Is IL not enough? Well think of enriching your ASP.NET web sites with JavaScript written in C#. Or using Ajax with scripts written in Visual Studio with Intelisense and refactoring. Or developing the Vista Sidebar Gadgets without writing a single line of code in Javascript!
Leasing Calculator I instantly lookd at the third possibility. since I have Vista on board I was thinking about writing my own Sidebar Gadget (you know the little programs written in HTML an JavaScript, sticked to the right side of your screen). Of course I wonted it to by at least useful 😉 I thought about writing a small Leasing Calculator. I had my leasing mathematics library ready, but it was written in C#. I didn’t feel like rewriting it in JavaScript – what for? So Script# was a blast for me. I had my Leasing Calculator gadget in view hours.
What do you need to start working with Script#:
1. download the latest binaries from Script# project page
2. install it
3. create new Visual C# -> Script# -> Sidebar Gadget project in Visual Studio
You will get quite useful project template. The inside of Content folder is your gadget. If you compile everything Script# will transform your C# into JavaScript and place it in this folder. The last thing you have to do is to copy this folder into your Vista Gadgets folder (C:\Users\user\AppData\Local\Microsoft\Windows Sidebar\Gadgets\). You will have to do the same every time you will compile. Surely it is something to automate. The easiest way is to use the Post-build event in your project and a small MSBuild script that will copy the needed files to the place they should by.
VS2005 post build event
$(WinDir)\Microsoft.NET\Framework\v2.0.50727\msbuild.exe $(SolutionDir)build.msbuild
And use this script:

<Project DefaultTargets="Deploy" xmlns="">
    <DeploymentSourceFiles Include="LeasingCalculatorContent***.*" />
   <Target Name="Deploy">
    <RemoveDir Directories="$(DeploymentFolder)" ContinueOnError="false"></RemoveDir>
    <Copy SourceFiles="@(DeploymentSourceFiles)"

So you are equipped with fully functional development platform for Vista Sidebar Gadgets.
One more thing. I do think that writing a JavaScript in C# is a good idea 😉 but if you are new to Sidebar Gadgets you probably would like to take one step by step tutorial. It would help to understand Gadgets on the low level an d will get you up to speed with Schipr# later.


Leave a Reply

Your email address will not be published. Required fields are marked *