RIA Development Center
Features Tips Events Videos
In Adam Flater's Flex blog, he suggests for teams getting started with RIAs that they:
  • Use Source Control
  • Create an easy designer/developer workflow
  • Select a micro-architecture, patterns and frameworks that work for your group
    Read more
    See more tips
  • Get regular email alerts when we publish new features!
    DevX RIA Development Update

    More Newsletters
    Get Started with Silverlight Using Visual Studio 2008 and Expression Blend 2 (cont'd)
    More Resources
  • MSDN: Microsoft Visual Studio 2008
        Downloads
  • Free Trial: Microsoft Expression Blend 2
  • 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."

    Previous Page: Transformation  
    Wei-Meng Lee is a Microsoft MVP and founder of Developer Learning Solutions, a technology company specializing in hands-on training on the latest Microsoft technologies. He is an established developer and trainer specializing in .NET and wireless technologies. Wei-Meng speaks regularly at international conferences and has authored and coauthored numerous books on .NET, XML, and wireless technologies. He writes extensively on topics ranging from .NET to Mac OS X. He is also the author of the .NET Compact Framework Pocket Guide, ASP.NET 2.0: A Developer's Notebook (both from O'Reilly Media, Inc.), and Programming Sudoku (Apress). Here is Wei-Meng's blog.
    Page 1: IntroductionPage 5: Writing the Logic Using Visual Basic
    Page 2: Obtaining the ToolsPage 6: Transformation
    Page 3: Getting StartedPage 7: Deploying Silverlight Applications
    Page 4: Building the User Interface Using XAML 
    We have a winner in the RIA Run contest! Check out the Contest Winners Gallery and see which entries took the top prizes. You can play the games, too! Also, be sure to check out our interview with the grand prize winner to see how he crafted his winning entry. (Silverlight 2 Beta 2 required)