Welcome to Pete Brown's 10rem.net

First time here? If you are a developer or are interested in Microsoft tools and technology, please consider subscribing to the latest posts.

You may also be interested in my blog archives, the articles section, or some of my lab projects such as the C64 emulator written in Silverlight.

(hide this)

Xap! App! Pow! Packaging and Application Startup in Silverlight 2 Beta 1 - Part 1

Pete Brown - 05 March 2008

This is Part 1 of a two-part series. Part 1 focuses on the new packaging model. Part 2 focuses on application startup and loading.

One of the nicest changes in Silverlight 2 is the addition of the new packaging model for managed code applications. While you can still use the loose file (xaml + JavaScript) methods for JavaScript applications in Silverlight 2, you must use the xap packaging model for managed applications. This is actually a good thing because of everything that xap brings to the table.

pmb_xap_app_comic

We'll keep the scope here to just managed code. However, you can still use the loose file model with JavaScript applications, and DLR projects have an auto-xap function which handles the xap goo for you.

Keep in mind that since this is Beta technology, anything you see here is subject to change.

Xap for Managed Code

Xaps (pronounced "Zaps"). really clean up the deployment of Silverlight applications in Silverlight 2. Under the covers, xap files are simply Zip files with the extension renamed. This allows you to use standard tools to create your own xap files or to inspect the contents of other xaps. This new packaging model also has several other benefits:

  • Compression greatly reduces the size of the download for the user. This is a big deal for performance.
  • The single-file deployment model makes web deployment easier and cleaner
    • If you want to create a portable application (we're doing one of those this spring/summer), all you need to deliver to someone is the xap package and, if they don't have something set up already, the page html markup to display the control
  • You can store the xap in a document library in SharePoint 2007 and serve up your Silverlight content from there. (in 1.1, there were issues with the path names for the DLLs)

To use xap files, make sure you have the mime type for xap application/x-silverlight-app set up in IIS. Under Windows 2008, this mime type is already present.

Also note that the <asp:Silverlight> control supports xaps, so you will be able to use that control right out of the gate. In fact, the default behavior of the project template in Visual Studio 2008 is to use the <asp:Silverlight> control for your test page. If you want the old html activation, check out what gets created in the ClientBin folder and use that.

BTW, "xap" doesn't actually stand for anything. :)

Xap Contents

The xap file itself contains your application DLLs, any assets you have packaged, and the AppManifest.xaml manifest file.

image

(ignore the 0% deflate on one of the DLLs. I understand that is an issue with the Beta 1 build. I would expect to see if addressed in the future)

DLLs

The DLLs are just what you would expect them to be: your compiled application code, targeting the Silverlight .NET framework. They are no longer just loose on the server like they were in 1.1.

Manifest

The xap manifest file (AppManifest.xaml) sets the starting point and lists all the components which make up the application.

Here is an example of the manifest file (the runtime version may not be exactly the same as you have). In this case, there are three DLLs that are included in the xap:

<Deployment 
    xmlns="http://schemas.microsoft.com/client/2007/deployment" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    EntryPointAssembly="PeteBrown.SilverlightWallpaperNavigator" 
    EntryPointType="PeteBrown.SilverlightWallpaperNavigator.App" 
    RuntimeVersion="2.0.30226.2">
  <Deployment.Parts>
    <AssemblyPart 
        x:Name="PeteBrown.SilverlightWallpaperNavigator" 
        Source="PeteBrown.SilverlightWallpaperNavigator.dll" />
    <AssemblyPart 
        x:Name="System.Windows.Controls" 
        Source="System.Windows.Controls.dll" />
    <AssemblyPart 
        x:Name="System.Windows.Controls.Extended" 
        Source="System.Windows.Controls.Extended.dll" />
  </Deployment.Parts>
</Deployment>

 

Content

Note that the content files which appear in the xap do not show up in the manifest. For this reason, it is very easy for you to crack open the xap after compile and add in any additional images you might want to have in there (assuming you somehow reference them in your code). Ideally, you'd do this all through Visual Studio and let it manage it, but this provides just one more level of flexibility for how you build your applications.

Look for an upcoming post (after part 2) that discusses the rules around locating your files and accessing them within the xap.

More to Come

Stay tuned for Part 2

     
posted by Pete Brown on Wednesday, March 5, 2008
filed under:      

10 comments for “Xap! App! Pow! Packaging and Application Startup in Silverlight 2 Beta 1 - Part 1”

  1. tweety123says:
    Hi Pett,

    In your last blog you mentioned, each Silverlight
    "Each running instance of Silverlight, in the current 1.1 alpha, gets its own copy of the CLR and its own app domain. " what is the current picture for Silverlight 4?
  2. tweety123says:
    Hi Pett,

    In your last blog you mentioned, each Silverlight
    "Each running instance of Silverlight, in the current 1.1 alpha, gets its own copy of the CLR and its own app domain. "
    what is the current picture for Silverlight 4?
  3. tweety123says:
    Thanks Pete!

    just one more doubt so, suppose each of the SL instance is loading SL toolkit dlls like charting dll, data input dll etc., then each instance will load these in its own app domain, or they can share that also, as these are not part of SL clr.

Comment on this Post

Remember me

7 trackbacks for “Xap! App! Pow! Packaging and Application Startup in Silverlight 2 Beta 1 - Part 1”

  1. Christopher Steensays:
    Sharepoint No VSE WSS for VS 2008 Until Summer [Via: Tariq ] WPF Podder v2 has been released! [Via:...
  2. Daniel Mothsays:
    Decompiling Silverlight 2 Apps � Enter the XAP
  3. POKE 53280,0: Pete Brown's Blogsays:
    How paths are resolved in Silverlight 2 can be somewhat confusing. This has come up a lot in the Silverlight.net
  4. TrackBacksays:
    Even before tools like Reflector made it easy, decompiling .NET applications has become standard operating procedure. Common reasons to decompile an application include learning how compiler's translate code, working around a library's limitations, or outright stealing another person's work. In the world of web browsers, it is so common that "view source" is a primary means of learning how to program...
  5. Canadian User Experiencesays:
    It has been three weeks since we annouced Silverlight 2 at MIX08. Many of you are excited to getting
  6. .Net Worldsays:
    When you build a Silverlight 2 application, you compile your source files (inc. XAML and embedded resources
  7. Microsoft Weblogssays:
    Starting last week on March 5th after Silverlight 2 Beta 1 was announced, a lot has been said about Silverlight