Wednesday, November 3, 2010

Configure an assembly for use with application library caching

  1. Create a mapping file in the same location as your assembly. This file must have the same name as your assembly, replacing the .dll file name extension with ".extmap.xml". For example, the Silverlight SDK assembly System.Windows.Controls.Data.dll has a mapping file that is named System.Windows.Controls.Data.extmap.xml.
  2. Add configuration data to the mapping file as shown in the following example, replacing the values in the assembly element to match your assembly.

<?xml version="1.0"?>
<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <assembly>
    <name>System.Windows.Controls.Data</name>
    <version>2.0.5.0</version>
    <publickeytoken>81bs3816af364e35</publickeytoken>
    <relpath>System.Windows.Controls.Data.dll</relpath>
    <extension downloadUri="System.Windows.Controls.Data.zip" />
  </assembly>
</manifest>

The name, version, and publickeytoken elements must match the corresponding assembly metadata. The relpath element indicates the assembly file name. Finally, the extension element indicates the name of the packaged external part through the downloadUri attribute. The downloadUri attribute value is used to populate the ExtensionPart.Source property in the application manifest, as shown in the following manifest excerpt.

<Deployment.ExternalParts>
  <ExtensionPart Source="System.Windows.Controls.Data.zip" />
</Deployment.ExternalParts>

The Source property indicates the name of an application library package or an absolute URI that identifies an application library package. Files identified by name only are retrieved from the same server location as the .xap file.

If the downloadUri value is a file name, Visual Studio provides the following support when you add a reference to the assembly:
  •          The build system packages the assembly into a zip file that has the specified file name. This file is copied to the output directory alongside the .xap file.
  •          If you add references to more than one assembly with the same downloadUri file name, the build system compresses them all into a single zip file.
  •         The .zip extension is not added automatically. Although the packaged file is a ZIP file, you can use whichever file name extensions that your server requires.
If downloadUri is an absolute URI, the build system will not package the assembly. Instead, you are responsible for zipping the assembly and deploying it to the specified URI. This is useful for creating a single repository of libraries used by multiple applications. However, you should consider the following issues when you use an absolutedownloadUri value.
  • If the URI is on a different domain than the .xap file, the domain must have a cross-domain policy file in its root folder.
  • A URI is a globally unique identifier and can reference a very specific assembly file. This means that you can and should use a different URI for different versions of your assemblies. Additionally, you should continue to maintain each version-specific URI and assembly that you create when you deploy new assembly versions at updated URIs. This helps avoid potential issues when a .xap file built with one version of Silverlight attempts to load a library built with another version.


No comments:

Post a Comment