Exforsys.com
 
Home Tutorials VB.NET 2005
 

.NET Assemblies

 

.NET Assemblies - Page 3

Page 3 of 3

.

.

.

Compiling Satellite Assemblies With Strong Names

To install satellite assemblies into the global cache they must have strong names. Strong-named assemblies are signed with a valid public/private key pair.


When an application is being developed it is likely that the developer does not have access to the final public/private key pair. In order to install a satellite assembly in the global assembly cache and ensure that it works as expected, the technique called delayed signing is used. Delay sign an assembly implies that a space in the file is reserved for the strong name signature at build time. The actual signing is delayed until a later date when the final public/private key pair is available.


Obtaining the Public Key

To delay sign an assembly, the developer must have access to the public key. Public keys can be obtained from the organization that will do the eventual signing or a public key can be created using the Strong Name Tool(Sn.exe)


The following Sn.exe command creates a test public/private key pair and saves it in the file TestKeyPair.snk. The –k option specifies to Sn.exe to create a new key pair and save it in the specified file.


sn –k TestKeyPair.snk

The public key can be extracted from the file containing the test key pair. The following command extracts the public key from TestKeyPair.snk and saves it in PublicKey.snk.


sn –p TestKeyPair.snk PublicKey.snk

Delay Signing an Assembly

Once the developer has obtained or created the public key, the Assembly Linker (Al.exe) can be used to compile the assembly and specify delayed signing.


The following Al.exe command creates a strong-named satellite assembly for the application MyApp from the strings.ja.resources file.


al /t:lib /embed:strings.ja.resources /culture:ja /out:MyApp.resources.dll /delay+ /keyfile:PublicKey.snk

The /delay+ option specifies to delay sign the assembly. The /keyfile: option specifies the name of the key file containing the public key to use to delay sign the assembly.


Re-signing an Assembly

At some later date, a delay-signed satellite assembly must be re-signed with the real key pair. This can be done using Sn.exe.


The following Sn.exe command signs MyApp.resources.dll with the real key pair stored in the file RealKeyPair.snk. The –R option specifies to Sn.exe to re-sign a previously signed or delay-signed assembly.


sn –R MyApp.resources.dll RealKeyPair.snk

Installing a Satellite Assembly in the Global Assembly Cache

A satellite assembly that has been compiled with a strong name is ready to install in the global assembly cache. The assemblies can be installed into the cache using the Global Assembly Cache Tool (Gacutil.exe).


The following Gacutil.exe command installs MyApp.resources.dll into the global assembly cache.


gacutil /i:MyApp.resources.dll

The /i option specifies to Gacutil.exe to install the specified assembly into the global assembly cache. As a result of this command, an entry is placed in the cache, which allows entries in this .resources file to be accessed. After being installed in the cache, the specified resource is available to all applications that are designed to use it.

All compiled satellite assemblies have the same name. They are differentiated at runtime based upon the culture specified at compile time in Al exe’s /Culture option and the directory location of the assembly. The satellite assemblies can be placed in expected directory locations..


Resources in Applications

Nearly every production-quality application needs to use resources. A resource is any non-executable data that is logically deployed with an application. A resource might be displayed in an application as error messages or as part of the user interface. Resources can contain data in a number of forms, including strings, images, and persisted objects. Storing your data in a resource file allows you to change the data without recompiling your entire application. Note that to write persisted objects to a resource file, the objects must be serializable.

The .NET Framework provides comprehensive support for the creation and localization of resources. In addition, the .NET Framework supports a simple model for packaging and deploying these localized resources.


Creating and Localizing Resources

The application's resources can be localized for specific cultures. This allows the developer build localized (translated) versions of the application. An application loads the appropriate localized resources based on the value of the CultureInfo.CurrentUICulture property. This value is set either explicitly in the application's code or by the common language runtime based on the locale for the current user on the local computer.


Packaging and Deploying Resources

The application's resources can be deployed in satellite assemblies. By definition, satellite assemblies only contain resource files. They do not contain any application code. In the satellite assembly deployment model, the developer can create an application with one default assembly (which is the main assembly) and several satellite assemblies. A satellite assembly should be created for each culture that the application supports. Because the satellite assemblies are not part of the main assembly, the developer can easily replace or update resources corresponding to a specific culture without replacing the application's main assembly.

It is important to determine which resources will make up the application's default resource assembly as it is a part of the main assembly. Any changes to it will compel the replacement of the main assembly. If a default resource is not provided for, an exception will be thrown when the resource fallback process attempts to find it. In a well-designed application, using resources should never throw an exception.

In this lesson we have studied in great detail the process of creating and using components and assemblies in VB.NET. In the lessons that follow we shall focus upon Data Binding.





First Page: .NET Assemblies


Read Next: Simple Data Binding



 
Related Topics


 

Comments


Rathina Kumar said:

  Excellent Explanation
November 9, 2006, 12:33 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape