Deploying Silverlight Applications
After your Silverlight application is completed, deploying it is very easy. For a production environment, there is no need to expose the source of your managed code; simply copy the compiled assembly to your web server. For example, you can copy the assembly you just created to see how easy the process is.
First, create a folder in your hard drive, say C:\MyFirstSilverlightApp.
Create an HTML page named Default.html and populate it with the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<!-- saved from url=(0014)about:internet -->
<head>
<title>Silverlight Project Test Page </title>
<script type="text/javascript" src="Silverlight.js"></script>
<script type="text/javascript" src="Default.html.js"></script>
<style type="text/css">
.silverlightHost { width: 640px; height: 480px; }
</style>
</head>
<body>
<div id="SilverlightControlHost" class="silverlightHost" >
<script type="text/javascript">
createSilverlight();
</script>
</div>
</body>
</html>
As you observe, you can simply copy the content from the
TestPage.html (from the Visual Studio 2008 project) and paste it into
Default.html. The important elements are highlighted in bold.
This HTML file references two JavaScript files: Silverlight.js and Default.html.js. Like before, you can also copy them directly from the files in Visual Studio 2008 project (after copying, simply rename TestPage.html.js to Default.html.js).
By default, the Default.html.js file uses Page.xaml as the UI for your Silverlight application (see Listing 5). Hence, copy the Page.xaml from your Visual Studio 2008 project into the C:\MyFirstSilverlightApp folder.
If you look into the content of Page.xaml, you will see that the Silverlight application is expecting to find the compiled assembly in the ClientBin folder. The name of the compiled DLL is OurFirstSilverlightProject.dll:
<Canvas
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="parentCanvas"
Loaded="Page_Loaded"
x:Class="OurFirstSilverlightProject.Page;
assembly=ClientBin/OurFirstSilverlightProject.dll"
Width="640"
Height="480"
Background="White"
>l
...
Hence, in
C:\MyFirstSilverlightApp, create a new folder named
ClientBin and copy the compiled DLL from the
ClientBin folder of your Visual Studio 2008 project's folder.
Figure 17 shows the content of the C:\MyFirstSilverlightApp folder. As you can see, you do not need to deploy the source code of your VB program, just the assembly.
 | |
| Figure 17. Content: What's inside the C:\MyFirstSilverlightApp folder. |
You can now configure the C:\MyFirstSilverlightApp folder as a virtual directory in IIS. Launch IIS (you can use the inetmgr command), right-click on the Default Web Site link and select New | Virtual Directory…. Give it the alias of Silverlight and specify C:\MyFirstSilverlightApp as the location of the folder. That's it!
You can now load the page using this URL: http://localhost/Silverlight/default.html.
You've seen how to create a Silverlight application using Visual studio 2008. You define Silverlight application UIs using XAML, which you can produce with Visual Studio 2008, Expression Blend 2, or manually. Hopefully, you've been inspired to explore Silverlight more deeply.
* This article originally appeared in the DevX Special Report: "A New Era for Rich Internet Applications."