What is XAP file in Silverlight



Target Audience: Beginners in Silverlight

When you start learning Silverlight and create your first Silverlight application, one thing you will notice is a XAP file along with HTML and ASPX files. The first time after running your Silverlight application you will see a XAP file in client bin folder. Before running a Silverlight application, you will not find a XAP file in the client bin folder.

Xap1.gif

Usually the following steps are followed while running a Silverlight application.

  1. Create a Silverlight Application
  2. Compile it to IL.
  3. Packaged it to XAP file.
  4. XAP file hosted in web server
  5. XAP file get downloaded to browser.

The flow diagram of a Silverlight application from creation to running at client browser can be depicted as below: 

Xap2.gif

If you notice whenever we are creating a new Silverlight application, you usually host a Silverlight application in a new Web Site. This is the web site which will host the XAP file. 
 

Xap3.gif

Every time you run the Silverlight application, Visual Studio automatically creates the XAP file and deploys to the web site.

XAP file is basic deployment in Silverlight.

Xap4.gif


XAP file is a ZIP file. It contains many files needed to run Silverlight application at the client browser. There are many files contained in a XAP file. 

Xap5.gif

Just to have a look at what all the files in a XAP file contains:
  1. Right click XAP file
  2. Rename the extension from XAP to ZIP
  3. Un Zip the ZIP file. You will find below files inside XAP file

There is one more way to easily extract the entire XAP file. Follow the steps as below:
  1. Open Command prompt as administrator
  2. Type command as below

    Xap6.gif
     
  3. Navigate to a folder containing the XAP file. On the right click on the XAP file; you can find the Extract All option.

    Xap7.gif


After extracting the XAP file or unzipping the Zip file, you can see there are at least two files:
  1. Silverlight application dll
  2. AppManifest.Xaml file.

    Xap8.gif


AppManifest.xaml file contains key information like:
  1. Version of Silverlight application is targeting
  2. Entry point of the application
  3. Name of the Silverlight application to be loaded
If you open AppManifest.xaml file, you will see that the preceding information is provided there. There is only one assembly of Silverlight application listed in the Deplyment.Parts section. If you have referred to any other assembly in the Silverlight application then the information of that assembly will also be listed in the Deployment.Parts section.

Xap9.gif

Algorithm how Silverlight application loads at client browser.

Step 1

HTML files gets loaded at client browser.

Step 2

Browser reads the HTML and finds the object tag and XAP file associated with object tag.

Xap10.gif

Step 3

Browser downloads the XAP file using Silverlight plugin installed at browser.

Step 4

Silverlight plugin reads the AppManifest.Xaml file and finds Entry Point of the application and the minimum version that the Silverlight application is targeting.

Step 5

Application gets executed at client browser.

Size of the XAP file is vital factor in performance of Silverlight application.

Xap11.gif

For better performance we should try to have size of XAP file as low as possible. All the resource files, images and Videos should be downloaded asynchronously at client browser. We should put images and media files on the server.

Up Next
    Ebook Download
    View all
    Learn
    View all