Update XAP file

27 Aug

Installing and running a Silverlight application out-of-browser makes it possible to create a better experience to the user. Sometimes it is necessary to update the installed application and with the build-in functionality in Silverlight it is a pretty straight forward operation.

Depending on your application the update should be done early on in the application. Normally I do it as part of the Application Startup event before setting the RootVisual.

First we need to make sure the update is only done if the user is actually running the application out-of-browser. Application.Current.IsRunningOutOfBrowser will be true if the user has installed the application and running it out-of-browser.


On the Application.Current object we can call the CheckAndDownloadUpdateAsync method. This will check if an update is available and download it. The method is an asynchronous method and we need to subscribe on its complete event to complete the update.

If an update is available (and have been downloaded) the UpdateAvailable property of event arguments for the complete event will be true. The update (the new XAP file) have been downloaded but not installed as it is not possible to remove the old XAP file since the user is actually using it to run the application. Therefore the user need to restart the application to install the update.


In some applications it is ok not to require the user to restart the application but in most scenarios it is the preferred solution – think about service updates and so on.

At the moment it is not possible to separate the check and download. It is not possible to check if an update is available and the ask the user if she wish to actually download the update. If the CheckAndDownloadUpdateAsync method is called both check and download will be invoked.

In most debug scenarios this update check will be annoying since the XAP file will be updated everytime you build your project. To overcome this I normally adds an if-not-debug (#if !DEBUG) around the update check.

Source code is available here.

by xamlgeek

2 Responses to “Update XAP file”


  1. Silverlight: Update XAP file - August 29, 2011

    […] Read original post by Thomas Martinsen at XAMLGeek […]

  2. Silverlight: Update XAP file – www.nalli.net - August 30, 2011

    […] Read original post by Thomas Martinsen at XAMLGeek […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: