Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Silverlight applications are client-side programs. In order for them to work, the code must be available on the customer's computer. The mechanism for deploying code in .NET is called an Assembly, which is nothing more than an especially configured executable file. In Silverlight, that will be a DLL file. This DLL file must be downloaded to the customer's computer before your application can start. Your code also uses other .NET classes. So, when you compile your App, you'll take dependencies on other .NET assemblies.
This means that these additional assemblies must also be available on the customer's computer. Silverlight has a number of assemblies that are compiled specifically for use by Silverlight applications. They contain all the types that are necessary to run your App plus hundreds of additional classes. In this regard, they are similar to the .NET and WPF assemblies. The Silverlight framework has been relentlessly reworked to be small and lean. This is to enable a fast install on the client's machine. It has also undergone a complete security refactoring to ensure that it is safe to run in a browser.
There are two sets of assemblies available. The first set is the Core Assemblies. These are essential libraries and are pre-installed on the client's computer. So, the way of saying this is when the user install Silverlight, the Core Assemblies are automatically copied to their machine. I've highlighted the Core assemblies on the right side of this slide in orange. There are five of them. The nice thing about this is your application does not need to download these files to the user's computer.
The second set are called the SDK Assemblies. These are additional Silverlight-specific libraries. They are useful but not critical. They are specifically compiled, so they work with Silverlight, but they are not automatically added to the user's computer. If you want to use something that's in the SDK assemblies, you have to do some additional work. First, you must add them to your project in Visual Studio or Expression Blend, and second of all, those must be downloaded to the user's computer. So, the deficit of this approach is your download is now bigger because you've decided to choose a Silverlight SDK Assembly.
Let's see how this works. I have switched back to Visual Studio. If you're following along with the Exercise Files, you're going to want to open the CoreRuntimeAndOtherAssemblies solution file. This is a simple project. A core message for this movie is to show you what files are generated. So, I just have it very simple application with one page. I am going to build my application, and then I am going to go look at my References folder. If you open the References folder, you'll note that I just have the Core assemblies in here, mscorlib, System.NET and so on. When I compile the application, it will create that DLL in my XAP file.
Let's go and take a look at those. I am going to go up here and choose Show All Files, and then I am going to scroll down to the Bin folder and double -click and drill down, double-click on Debug and we're going to find this XAP file. You might recall that the XAP file is just a ZIP file with another extension on it. In order to look at the contents of this I just need to go and change the extension to zip, satisfy Visual Studio that I know what I am doing by clicking on Yes, and then double-click on this ZIP file.
Now what I want you to see here is there is only my DLL and a single AppManifest file. None of the Core DLL files are in here because they are already on the user's computer and Silverlight assumes that. I am going to add a reference to an SDK assembly. I think before I do that though I should delete the ZIP file, because it's going to generate another XAP file and this will make things easier for me later. Then I am going to go up to my References folder, and I'm going to tell Visual Studio to use a SDK Assembly.
Right-click, choose Add Reference, scroll down, and find System.Windows.Controls. This assembly contains interesting controls like the TreeView control. Click OK and what do you see that's different? I now have a new node in the Reference folder called System.Windows.Control. If I compile my application and go down to my Debug folder and open up this XAP file, again, I'll have to change the extension, choose Yes, double-click on the ZIP and here is what I want you to see. System.Windows.Controls.dll is inside my XAP file.
When I deploy my application and the user runs it for the first time, it's going to take this file, download it to the user's computer, and it's now going to have a copy of System.Windows.Controls.dll for it to use locally. It's also possible for you to use your own assemblies. So, I'll show you an example of how to do that. I am going to go up here and collapse my main Silverlight Project, and then I am going to add a brand new project to the Solution. I am going to right-click on the Solution and choose Add>New Project.
What I want to do is build a library that I will use in multiple Silverlight applications. So, the key thing that I need to do here is tell Silverlight this is a special version of a .NET assembly that works with Silverlight Apps, because they are different, they have different security contexts than say .NET WinForms or .NET WPF Applications. So, I use the Silverlight Class Library, not the normal .NET Class Library. So, I'll choose Silverlight Class Library, and I'll call it something like LyndaLib for lynda Library and then I'll create a Class in here, add a new class.
I have this VideoGenerator Class, and now I am ready to compile. I have two projects. So, if I tell Visual Studio to compile, it's going to compile both of these. What I want to have happen is I want this DLL that's generated for LyndaLib - let's go look at that, here is the Bin folder, here is the LyndaLib.dll - what I want to do is move that into my Silverlight XAP file.
It's really easy to do in Visual Studio. I go to the Silverlight application and I add a reference here, just like before, Add a Reference. Remember I am in the Silverlight App now, not the lynda Library, and I click on the Projects tab. These are all the known the .NET libraries that work with Silverlight. It doesn't know about my library however, so I will go to Projects and choose LyndaLib. By doing this, Visual Studio will help me by every time I do a compile, it will first make a copy of LyndaLib in this folder, and then I will take it and copy it over to this Bin folder.
Let's see how that works, Build Solution. Now it says two successful builds. I also can see I have a reference now to LyndaLib in my References folder and if I drill down into the Bin folder, I'll have to delete this ZIP file, so I don't get a name conflict later. I am going to rename the XAP file. You should be getting used to this by now. Press OK or Yes, and then double-click on the ZIP file, and what's the key thing to takeaway here? LyndaLib is in my XAP file.
So, now this will get downloaded to the user's computer and it's available. Can you see any problems with this? I can see one. Every single time you run this application it has to copy these files to the local computer. If these are big files, it's going to take a while. That's going to mean that your application is going to be slower starting. Now what I can do is I can cache these. Silverlight has special cache. It's not the web cache. It's a special Silverlight cache. What I can do is tell it to stash these in the cache. I will stash these files in the cache. And then the first time I run the application, it will put them in the Silverlight cache.
The second time I run the application, it will use the local copy and I won't have to download these anymore. This is another simple fix. I'll show you how to do it. We'll go up to Properties. Again, this is my Silverlight App, double-click on the Properties node, come over here to the Silverlight tab, and choose Reduce XAP size by using application library caching. Done. Save the project. We'll choose build. Let's see what's different. There is the ZIP file for System.Windows.Controls and here is my CoreRuntimeAndOther. I don't need that, and I'll delete this one again.
Now, there is two ZIP files and they'll both get downloaded and the contents of this file will go in the local cache. By now, you should have a better idea of what files are created and stored in the XAP file whenever you do a compile.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 93497 Viewers
82 Video lessons · 104374 Viewers
71 Video lessons · 76494 Viewers
56 Video lessons · 107815 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.