Silverlight: Anatomy of an .XAP file

5. March 2008

Silverlight 2 Beta 1 just came out this morning, so I started checking it out immediately. I installed the Silverlight Tools for Visual Studio and noticed that when a Silverlight Application is compiled a .xap file is created that contains the application. But, what exactly is a .xap file, and what exaclty is in there?

What is an .xap file?

A .xap file is basically a compiled Silverlight application. The file is actually a .zip file that contains all the files necessary for the application. Just rename the .xap file to have a .zip extension and then you can open it up to see its contents. Just try it yourself.

What files are contained within the .xap file?

The .xap file contains an application manifest (AppManifest.xaml) file and all the necessary DLL's that are required by the application. The first DLL contained is the compiled version of you application and has the same name of your application. In my test I created an application names "SilverlightApplication1", so the DLL is named "SilverlightApplication1.dll". The rest of the DLL's are the dependancies the application requires.

What is the AppManifest.xaml file?

First lets look at an example AppManifest.xaml file:


<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="SilverlightApplication1" EntryPointType="SilverlightApplication1.App" RuntimeVersion="2.0.30226.2">

  <Deployment.Parts>

    <AssemblyPart x:Name="SilverlightApplication1" Source="SilverlightApplication1.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>

The first element in the AppManifest.xaml is a Deployment node. This node defines the application and contains child AssemblyPart nodes.

As you can see the AssemblyPart nodes define what assemblies (DLLs) are contained within the .xap file, and give each of them a name.

Now, if you look back up to the top, you'll see the Deployment node has EntryPointAssembly and EntryPointType attributes. The EntryPointAssembly attribute defines which assembly defined below (as a child AssemblyPart node) is the main assembly (DLL) for the application. And, the EntryPointType attribute specifies the Class contained within the assembly (DLL), defined in the EntryPointAssembly attribute, is the main class that will be instantiated to start the application.

The Deployment node also has a RuntimeVersion attribute that defines the version of Silverlight the application is built for.

Conclusion 

There you go, now you have a basic understanding of what an .xap file is. This article was written using Silverlight 2 Beta 1, so things may change in the final release, but I image the basics described here will still remain the same.

I'm sure there are more child nodes and attributes that can be defined within the AppManifest.xaml file, but I have yet to see what they are since, I'm still new to Silverlight 2.0.

Silverlight



Comments

4/24/2008 7:21:16 PM #
Pingback from brightsparc.wordpress.com

Silverlight 2.0 leaps&bounds ahead « Fluent.Interface
4/24/2008 7:22:00 PM #
Pingback from brightsparc.wordpress.com

Silverlight 2.0 leaps&bounds ahead « Fluent.Interface
8/31/2008 11:18:22 AM #
Pingback from weblogs.asp.net

Silverlight 2.0: Beyond the Basics - Craig Shoemaker
12/11/2008 12:27:52 PM #
Pingback from blogs.estatic.org

BusinessRx Reading List : XM Radio Player Part III : Choices
12/12/2008 3:26:59 PM #
Pingback from odetocode.com

K. Scott Allen : XM Radio Player Part III : Choices
7/14/2009 9:58:49 AM #
Pingback from ria.com.mx

Rich Internet Applications » Silverlight 3 disponible y recargado
9/23/2009 10:37:00 PM #
Pingback from vinodsardar.wordpress.com

Reading Content from XAP and Resource in Silverlight «  All About .NET
2/12/2010 9:29:27 AM #
Pingback from syedmehdi.wordpress.com

Creating TextBox, Button and Label controls in Silverlight « Syed Mehdi's Blog
Comments are closed