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: <pre class="csharpcode">«/span>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"> «/span>Deployment.Parts> «/span>AssemblyPart x:Name="SilverlightApplication1" Source="SilverlightApplication1.dll" /> «/span>AssemblyPart x:Name="System.Windows.Controls" Source="System.Windows.Controls.dll" /> «/span>AssemblyPart x:Name="System.Windows.Controls.Extended" Source="System.Windows.Controls.Extended.dll" /> </Deployment.Parts> </Deployment></pre>
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.
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.