By default, if the SL project references some otherProgramWhen compiling and packaging, these DLL files are all packaged into an xap file. As more DLL files are referenced, The xap files become larger and larger.
This is not the most serious problem. If you really need to use these DLL, it will be big. The capacity will definitely increase when you use it. However, if multiple SL projects reference the same assembly, these DLL files are repeatedly packaged into each xap file.Repeated downloadThe bandwidth usage of these DLL files is too low.
To improve this situation, SL references the concept of "application library cache". In the SL project of vs2010, open the properties page of the SL project and you will see an option: "Reduce xap size (r) by using application library cache )"
Check the final clientbin directory, and you will find that some other Assembly referenced by the project has been separated into a zip file.
A bit more nagging: When myslapp.xapis under download, will the notification go to system.runtime.serialization.json.zip?
Secrets: Find a decompressed software (such as WinRAR, WinZip, and 7-zip) and use it to open the myslapp. xap file, appmanifest. decompress the XAML package and open it in Notepad. The content similar to the following is displayed:
<Deployment xmlns = "http://schemas.microsoft.com/client/2007/deployment" xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml" entrypointassembly = "myslapp" entrypointtype = "myslapp. APP "runtimeversion =" 4.0.50826.0 "> <deployment. parts> <assemblypart X: Name = "myslapp" Source = "myslapp. DLL "/> </deployment. parts> <deployment. externalparts> <extensionpart source = "system.runtime.serialization.json.zip"/> </deployment. externalparts> </deployment>
Here <Extensionpart source = "system.xml.serialization.zip"/> System.xml.serialization.zip in the same directory will be downloaded at the notification runtime. During the first loading, all xap and related ZIP files will be downloaded. When you browse the page again, if the cache is not cleared, the zip file will be read directly from the cache, the download will not be repeated.
However, there is a problem that only strongly-named assembly can do this. If the class library is developed by the user, you can check this option by default, in the end, the DLL will be packaged together into the xap file. How can we make the self-developed SL class library use the cache?
Step 1: First sign your SL class library assembly (with strong names)
This step can be completed by using vs2010, see
Then re-compile
Step 2: Create an XML ing File
Open the compiling output directory (default: bin \ DEBUG directory) of the SL class library and create an XML file. The file name rules are as follows:
For example, if the DLL file output by the class library is mytools. dll, the XML file must be mytools. extmap. XML, that is"DLL file main name +. extmap. xml"(And this file must be in the same level as the DLL file), the content is as follows:
<? XML version = "1.0"?> <Manifest xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: XSD = "http://www.w3.org/2001/XMLSchema"> <Assembly> <Name> mytools </Name> <version> 1.0.0.0 </version> <publickeytoken> c934ea1d360b6e15 </publickeytoken> <relpath> mytools. DLL </relpath> <extension downloaduri = "mytools.zip"/> </Assembly> </manifest>
Explanation: Name is the complete name of the SL class library assembly version refers to the version number (must be consistent with assemblyinfo. the version number in CS is the same.) publickeytoken can be viewed through the sn.exe tool (which will be discussed later). The above three items must be consistent with the Assembly metadata. The relpath is the physical file name of the DLL file downloaduri token to view the publickeytoken: open vs.net --> tool --> external tool-> Add the title and enter the get Sn token (you can also change it to your preferred name). Run the c: \ Program Files (x86) command) \ microsoft sdks \ windows \ v7.0a \ bin \ netfx 4.0 tools \ sn.exe (full path of sn.exe) parameter input-T $ (targetpath) and check "use output window, under the vs.net tool menu, a menu item get Sn token should be generated. In the solution window, select the SL class library project, compile it, and then select the "get Sn token" menu, you can see the corresponding publickeytoken, for example:
Step 3: reference this DLL (or SL class library) in the SL project, and check "reduce xap size (r) by using application library cache" correctly.
In the clientbin directory, the output similar to the following is displayed:
We can see that vs has automatically packaged mytools. DLL into a zip file, and then checked the appmanifest. XAML content in myslapp. xap.
<Deployment xmlns = "http://schemas.microsoft.com/client/2007/deployment" xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml" entrypointassembly = "myslapp" entrypointtype = "myslapp. APP "runtimeversion =" 4.0.50826.0 "> <deployment. parts> <assemblypart X: Name = "myslapp" Source = "myslapp. DLL "/> </deployment. parts> <deployment. externalparts> <extensionpart source = "mytools.zip"/> <extensionpart source = "system.runtime.serialization.json.zip"/> <extensionpart source = "system.xml.serialization.zip"/> </deployment. externalparts> </deployment>
Note <extensionpart source = "mytools.zip"/> that vs automatically adds this line to us.
Tip: If you have processed the above, vs.net still cannot split the Assembly into a zip package. Please check that the"Copy local"Whether the attribute is false. If not, change it to false.
ExampleSource codeDownload: http://files.cnblogs.com/yjmyzz/SL_App_Cache_Demo.7z
Note: Application cache does not apply to OOB