Wednesday, June 13, 2007

Silverlight with Visual Studio .NET 2005 and

I just got back from Budapest's Remix 2007. It was an awesome conference where I got amazed by the new Silverlight 1.1 possibilities. Thus the first thing I did was to try build a simple ‘Hello world’ application using First of all, although the guys in Microsoft have Silverlight support in visual studio Orcas, there is no integration (at least as far as I know) with vs 2k5. Looking around on the net, I found a tip given by Scott Louvau to Bryant Likes on how to create a silverlight c# application with vs2k5.
Well, in VS2005 you can create a class library which will build against the Silverlight runtime, but it's a little work.
  1. Create a Class Library/
  2. Remove all references from it.
  3. Right-click on the Project and pick Properties.
  4. On the Build tab, click Advanced and check 'Do not reference mscorlib.dll'
  5. Manually add references to mscorlib, agclr, System,System.Core, System.Silverlight, and System.Xml.Core from the Silverlight install folder (\Program Files\Microsoft Silverlight\)

At this point your build outputs should be Silverlight consumable binaries. It looks
like the equivalent command line call to csc.exe (the C# compiler) should include the references to the mentioned binaries and the /nostdlib option but may require others as well.

The above mentioned solution could not be implemented on a VB project because there was no way I could tell the vb compiler to not reference mscorlib.dll as the compiler requires the Microsoft.VisualBasic.dll which refers to system.dll and finally we get a reference to mscorlib.dll. Thus I had to find a workaround for this…

The idea was to trick visual studio and use the silverlight framework instead of the normal .net 2.0. So I created a class library project based on the .NET Compact Framework 2.0 for Windows CE 5.0. Thus I got the compiler looking for the framework in the following path: "C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v2.0\WindowsCE\"

Since I am not currently developing any windows CE application I simply replaced the contents of that path with the ones from the silverlight framework (located at "C:\Program Files\Microsoft Silverlight\").

So, we have tricked the compiler to not use the regular .net framework. From now on the things are quite straight forward.

  1. Create a Class Library.

  2. Remove all references from it.

  3. Manually add references to mscorlib, agclr, System, System.Core, System.Silverlight, and System.Xml.Core from the Silverlight install folder (\Program Files\Microsoft Silverlight\)

Done. Create your xaml, html and js files and you are ready to experience the silverlight experience through visual studio 2005 and :)

Bryant Likes offers a c# example of the Hello world application on his blog .

Thus I converted the above example in to the following hello world example:


Andreas Botsikas said...

After posting the same article in Greek in (thread, kelman contributed the following comment:

The Vb Runtime is required for two reasons. First of all it’s the backward compatibility with vb 6 (MsgBox, Left, Right, etc) and moreover it contains a lot of helper functions which are not supported by IL and without then the code would not compile.

In VS 2005 it is impossible to not reference them. But, in the early beta 2 of vs 2008 there will be a compiler switch (mainly /vbruntime) which will allow compilation without the default reference to Microsoft.VisualBasic.DLL. This switch can be used only through command-line since the UI does not support it yet.

Cheers kelman for the contribution.

Aidan Ferguson said...

Silverlight facilitates the WPF movement design. This is not only time centered but also allows you determine the begin and end circumstances and allows you get there.