A task that finally worked itself to the top of my to-do list is preparing my SharePoint development environment for Silverlight. I kept a reference to an article written by Karine Bosch back in November; Creating a SharePoint Web Part that hosts a data binding Silverlight application. Since the article was published Silverlight 2 went RTW and I am starting from an environment with no prior Silverlight installation.
Where to begin?
First I had to download and install the Microsoft® Silverlight™ Tools for Visual Studio 2008 SP1. When The installation package complained that service pack 1 was required for Visual Studio 2008 so I had to download and install that.
45 minutes* later and my SharePoint development VM was running Visual Studio 2008 SP1 and Silverlight Tools for Visual Studio which includes the SDK.
Coding the solution
Karine’s article is excellent as it walks through the components of the solution and explains what needs to be done and why. However, I still found that I needed to download the ZIP file of the code from Karine’s blog and cut, paste and modify it (namespaces etc.) into my own solution. Karine has updated the code to work with the RTW version of Silverlight 2 and explained the changes in another blog post. I would recommend running through Karine’s article again at this point to cement your understand of the solution (I always find working code the best documentation).
Preparing the server
Three steps are required to enable WSS 3.0 or MOSS 2007 server(s) to run Silverlight.
- Drop the System.Web.Silveright.dll into the Global Assembly Cache. Having installed the Silverlight Tools for Visual Studio 2008 (see above), this assembly will be located at (C:\)Program Files\Microsoft SDKs\Silverlight\v2.0\Libraries\Server.
- Update the web.config file of the SharePoint application on all front end web servers to run on the .NET 3.5 framework. Karine published a really useful blog post that references an excellent post by her colleague Jan Tielens in which he steps through what he calls the “lazy” way to update your web.config files to .NET 3.5. This is exactly the technique I used because far from lazy, I think this is the safest (and therefore most sensible) method. As Karine points out in her blog post, after using Jan’s technique you will need to add a reference to the Silverlight assembly in the <system.web><compilation><assemblies> section as follows; <add assembly=”System.Web.Silverlight, Version=126.96.36.199, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ />
- Add a new MIME type to allow Silverlight applications to run in your SharePoint web application. In IIS open the properties dialog for the SharePoint web application and select the HTTP Headers tab.
Click on the MIME Types… button and Add a new MIME Type for Silverlight applications.
The Extension of the new MIME Type is “.xap” and the MIME type is “application/x-silverlight-app”.
Another blog post I found really useful was What I did to get Silverlight Working in SharePoint in Today’s Webcast by Andrew Connell. If you know SharePoint you will know Andrew Connell and if you don’t then you don’t! (If you only check a few blogs regularly then make one them Andrew Connell‘s, in my opinion he is Mr SharePoint Community).
NB I am not aware that these steps need to be performed in any particular order, however, the application pool of the SharePoint web application will need to be recycled so this should be planned in a production environment.
After getting Karine’s excellent sample running in my own development environment I was very impressed with the look of the web part, it tells me that Silverlight is the way to go to address the rather aesthetically challenged standard SharePoint UI. However, all of that would be next to worthless to me if I couldn’t debug it in situ. Attaching the Visual Studio debugger to a SharePoint application is a proven, reliable and extremely effective technique and as it turns out, debugging a Silverlight application in this configuration is just as straight forward. Set your breakpoints in Visual Studio and from the Debug menu select Attach to Process. In the resulting dialog box click the Select… button to display the Select Code Type dialog and check the box for Silverlight. Now, under Available Processes, look for an iexplorer.exe process with Silverlight listed under Type and a Title that matches the title of the SharePoint page.
I anticipate there will be a pretty steep learning curve if I am to make Silverlight my user interface tool of choice, however thanks to Karine’s excellent article and code I now have a solid foundation on which to build up my knowledge.
*actually 45 minutes is what it should have taken, it actually took more like 2 hours as I kept getting the following error from the Visual Studio 2008 SP1 installer: Microsoft .NET Framework 2.0 Service Pack 2 – Update ‘.NET Framework CLR’ could not be installed. Error code 1603. After trawling the logs and several forums I found this thread that made me suspect a file access issue however I don’t run any AV on my VMs so I elected for a straight forward reboot and hey presto!