Installing Silverlight OOB application using a setup project
Introduction
In this article we are going to see about how to install a Silverlight OOB application through a setup project. Silverlight OOB applications shortly OOBs are much like desktop applications that can be installed, launched and uninstalled. These OOBs are normally installed from the browser by right clicking the Silverlight control and selecting Install app into this computer, but there are times we have to look into alternate ways of installation for example when we want the OOB app to be easily distributable from machine to machine or to install the OOB as part of batch installation etc. This article helps to understand how to install an OOB application through a setup project.
I've split the article into below main sections to help readers understand easily.
- A little theory - In this section we are going to see about what is the sllauncher and how we can use it to manually install, uninstall an OOB application from the command prompt.
- Project Plan - In this section we are going to discuss about our project plan and what are the things need to be configured in the setup project.
- Custom Installer - In this section we will see about the Installer base class methods that need to be overridden and how to practically invoke the sllauncher for installing or uninstalling a sample application.
a. What is the sllauncher?
When we install the Silverlight plugin a set of things are downloaded to the machine. If we navigate to the %ProgramFiles%\Microsoft Silverlight\ folder we can see the following.
Fig a. Microsoft Silverlight Installation Directory
- 4.0.51204.0 - this folder contains all the Silverlight framework assemblies.
- sllauncher.exe - the process that will be invoked when we install, launch or uninstall any OOB application.
b. sllauncher.exe options
To know more about various options of sllauncher open the command prompt and run,
"%ProgramFiles%\Microsoft Silverlight\sllauncher.exe"
We'll see the below error message box,
Fig b. sllauncher.exe options
That clearly points out we can't use sllaucher.exe
directly without passing some parameters and the message box also displays the various options available with it. In the below table I listed down the various options and for what they are used for.
Option | Description |
---|---|
app_id | Whenever an OOB application is installed, the XAP and the associated content are located under a uniquely named folder and the unique name is called as app_id , this parameter is used by sllauncher to located the installed app when we launch it. |
/install: <file path to XAP> | This option is used to install the OOB application passing the physical path of the XAP file ex. /install: D:\SilverlightSamples\SampleOOB.xap |
/emulate: <file path to XAP> | This option is used to launch an OOB application in emulation mode without even installing it. |
/origin: <original app uri> | This option specifies the Uri where the XAP file have come from. This Uri is used for security purposes and auto-updates. For ex. /origin: http://mywebsite.com/SampleOOB.xap |
/overwrite | Overwrite any previously installed version when installing the current version. It's a good practice to use this along with /install switch. |
/shortcut: <desktop|startmenu |desktop+startmenu|none> | This option specifies the places where the shortcuts has to be created in desktop or startmenu or both or none. |
/debug | Including this option launches the application in debug mode. |
Let's assume we have a sample OOB application named SampleOOB.xap
located under folder D:\SilverlightSamples\
and the XAP is hosted in http://mywebsite.com/
.
For installing the OOB application we have to run the following command from the command prompt,
"%ProgramFiles%\Microsoft Silverlight\sllauncher.exe" /install:D:\SilverlightSamples\SampleOOB.xap /shortcut:desktop+startmenu /origin:http://mywebsite.com/SampleOOB.xap /overwrite
For uninstalling the application we have to run the command,
"%ProgramFiles%\Microsoft Silverlight\sllauncher.exe" /uninstall
/origin:http://mywebsite.com/SampleOOB.xap
Project Plan
a. Solution
Our plan is to run the above commands from the installer. When the setup installs we have to install the Silverlight OOB application by launching the sllauncher passing the installation parameters and when uninstalls we have to uninstall our already installed OOB application using the sllauncher passing the necessary parameters. For that, we have to create a custom installer class that is placed in a separate assembly.
Below is the solution explorer view of the attached source code,
Fig c. Project Solution Explorer View
Our solution contains four projects.
- SlApp - Sample silverlight application.
- SlInstaller - Assembly that contains our custom installer class.
- SlWeb - The web application that hosts the XAP component.
- SlSetup - Setup project.
b. Things to be configured in the setup project
The following are the configurations we have to do in the setup project.
- Right click the setup project Add -> Project Output -> Primary output(SlApp).
- Right click the setup project Add -> File ->
SlApp.xap
located in theClientBin
of the web application. - Right click the setup project View -> Custom Actions.
Fig d. Configuring Custom Actions in Setup Project
Right click each of the custom actions (Install, Commit..) in the left column and select Custom Action -> Application Folder -> Primary output from SlInstaller(Active).
- Pass the installation directory path in the
CustomActionData
property that we'll retrieve in the installer class to locate theSlApp.xap
path. To do this right click the Primary output from SlInstaller(Active) node under Install custom action -> Go to Properties -> Enter the CustomActionData as/INSTALLDIR="[TARGETDIR]\"
.
Fig e. Passing parameter in CustomActionData
The Custom Installer project SlInstaller
contains the class SlInstaller
that extends the built-in Installer class for that we have to add the reference to System.Configuration.Install
assembly. [Note: Don't forget to add the RunInstaller attribute over the class].
/// <summary> /// Custom Installer Class /// </summary> [RunInstaller(true)] public class SlInstaller : Installer { }
The Installer class contains lot of virtual methods, but we have to override only couple of them OnAfterInstall
and Uninstall
. You may have a doubt why we are overriding OnAfterInstall
instead of Install
, we are doing so because for installing the OOB application we need the XAP file(SlApp.xap
) and that will be downloaded to the installation directory only after the base installation is done.
In the OnAfterInstall
we are going to run the command to install the OOB application and in the Uninstall method we are going to run the command to uninstall the OOB application.
/// <summary> /// Custom Installer Class /// </summary> [RunInstaller(true)] public class SlInstaller : Installer { protected override void OnAfterInstall(IDictionary savedState) { //Run command to install Silverlight OOB app. base.OnAfterInstall(savedState); } public override void Uninstall(IDictionary savedState) { //Run command to uninstall Silverlight OOB app. base.Uninstall(savedState); } }
First write the code for installation in the OnAfterInstall
method. For installing the OOB app we need the following parameters to form the command-line string.
- sllauncher.exe path
- XAP file's physical path
- XAP file's origination Uri
Environment
class we can get the correct path without hard-coding.
string sllauncherPath = string.Format("{0}\\Microsoft Silverlight\\sllauncher.exe", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
We can get the XAP file's physical path that we passed through the CustomActionData
from the Parameters
collection in the Context
object.
//getting the installation folder to get the XAP file's physical path. string installDir = Context.Parameters["INSTALLDIR"]; string xapPath = string.Format("{0}{1}", installDir.Substring(0, installDir.Length - 1), "SlApp.xap");
The XAP is hosted in the sample web application(SlWeb
) and let's say it is running in port 5555 so the Uri of the XAP originated will be http://localhost:5555/ClientBin/SlApp.xap
.
public const string originUri = "http://localhost:5555/ClientBin/SlApp.xap";
Now form the command-line string args
and create a new process to invoke sllauncher.exe.
//form the command-line string string args = string.Format(@"/install:""{0}"" /origin:""{1}"" /shortcut:""desktop+startmenu"" /overwrite", xapPath, originUri); var startInfo = new ProcessStartInfo { CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, FileName = sllauncherPath, Arguments = args }; using (var process = Process.Start(startInfo)) { process.StandardOutput.ReadToEnd(); }
In the above code we are creating a new ProcessStartInfo
instance that contains the sllaucher.exe process path in FileName
property and the command-line arguments in Arguments
property, then we are creating a new Process
instance passing the ProcessStartInfo
instance to the constructor.
That's all the code for installation. The code for uninstallation is much similar as above and it has to be written in the Uninstall method as below.
public override void Uninstall(IDictionary savedState) { //Uninstall Silverlight OOB app. //getting the sllauncher.exe with complete path string sllauncherPath = string.Format("{0}\\Microsoft Silverlight\\sllauncher.exe", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)); string args = string.Format(@"/uninstall /origin:""{0}""", originUri); var startInfo = new ProcessStartInfo { CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, FileName = sllauncherPath, Arguments = args }; using (var process = Process.Start(startInfo)) { process.StandardOutput.ReadToEnd(); } base.Uninstall(savedState); }
Demo
I've attached the sample source code that contains all the projects listed in the article. Please go through it and post your valuable comments.
References
Post Comment
XpsC3u Useful information for all Great remarkable issues here. I am very satisfied to look your article. Thanks a lot and i am taking a look ahead to touch you. Will you kindly drop me a e-mail?
k4Z5ff Thanks again for the blog post.Much thanks again. Great.
GtQgfT There is certainly noticeably a bundle to comprehend this. I assume you might have made particular great factors in functions also.
cJpyaR Thanks for the article post.Really thank you! Awesome.
BKAGuO What a funny blog! I actually enjoyed watching this humorous video with my relatives as well as with my friends.
qlMjzc There is apparently a lot to identify about this. I assume you made some nice points in features also.
xvOTCG Really informative blog.Much thanks again. Awesome.
This website was how do you say it? Relevant!! Finally I ave found something that helped me. Many thanks!
rPynRC There is obviously a bundle to identify about this. I feel you made certain nice points in features also.
zqoW9z Well I sincerely enjoyed reading it. This subject provided by you is very useful for good planning.
ZA9HPe Well I truly liked studying it. This post provided by you is very helpful for accurate planning.
AZgcL4
QDSXdi Really enjoyed this blog post.Thanks Again. Really Cool.
s8Ju4N You made some nice points there. I did a search on the subject matter and found most persons will approve with your blog.
Bxuuqp I cannot thank you enough for the blog post.Really looking forward to read more.
TsqqsE Wow, great blog article.Really looking forward to read more. Want more.
vlbZEd This blog is without a doubt entertaining additionally informative. I have picked many handy things out of this source. I ad love to return again soon. Thanks a lot!
OHYQ2H Thanks-a-mundo for the blog article.Much thanks again. Awesome.
t6rUhi Great web site. A lot of helpful information here. I'm sending it to some buddies ans additionally sharing in delicious. And certainly, thanks on your effort!
NsTVNX It's hard to search out knowledgeable folks on this subject, but you sound like you recognize what you're talking about! Thanks
hI6xyx Heya i am for the first time here. I found this board and I find It really useful & it helped me out a lot. I hope to present one thing back and help others like you helped me.
wtyFjI Nice weblog here! Additionally your site so much up very fast! What web host are you using? Can I am getting your associate hyperlink to your host? I wish my site loaded up as fast as yours lol
dhPpal I really like and appreciate your post.Really thank you! Will read on...
BG77fG Say, you got a nice blog post.Really thank you! Great.
Qu1rkb I loved your article post.Really thank you! Awesome.
8cHa2y I loved your article post.Thanks Again. Really Cool.
8fn3Qe Thanks so much for the blog post.Really thank you!
91ne5d Appreciate you sharing, great article.Much thanks again.
5904nw I loved your blog.Really looking forward to read more. Keep writing.
fUn4ir Thanks again for the blog. Want more.
bE5YZp Major thanks for the blog.Really looking forward to read more. Really Cool.
4eWg3w Really informative post. Want more.
I like the first point you made there, but I am not sure I could reasonably apply that in a postive way.
Thanks for share very nice info. Your weblog could be very goodI am impressed by the information you have got on this blog. It shows how nicely you perceive this subject. Bookmarked this web page, will come back for more. You, my good friend, ROCK! I discovered just the knowledge I already searched in all places and just couldn't find. What a perfect site. Like this website your website is one in all my new favs.I like this info introduced and it has given me some form of desire to succeed for some cause, so thanks
Is it alright to post some of this on my website if I include a reference to this page?