<<

.NET A ssembli es

This material is based on the original slides of Dr. Mark Sapossnek, Computer Science Department, Boston University, Mosh Teitelbaum, evoch, LLC, and Joe Hummel, Lake Forest College

Assemblies Overview

Š Assemblies can be:

„ Static: DLL, EXE z Uses existing COFF binary format Š Via existing extension mechanism

„ Dynamic Š Create assemblies with

„ .NET Framework SDK

„ Visual Studio.NET

„ Your own code z Dynamic assemblies AsseAssembliesmblies Components of an Assembly

Š Manifest

„ Metadata about the itself Š Type

„ Completely describes all types defined in an assembly Š Managed code

„ Intermediate Language (MSIL) Š Resources

„ For example , . bmp, . jpg

Assemblies Components of an Assembly

ParcelTracker.DLL

Manifest

Type Metadata

MSIL

Resources Assemblies Demo: ILDASM.EXE & Private Assemblies

Š Allows you to inspect the metadata and disassembled IL code in an assembly Š Great way to see what’s really going on Š Use ildasm /? to see the various options

Assemblies

Š AfA set of assembli blihbfdbes that can be referenced by any application on a machine Š Should be used only when needed „ Private assemblies are preferred Š Located at %SystemRoot%\assembly „ (c:\windows\assembly) Š Add assemblies by „ Installer program „ gacutil.exe „ Windows Explorer z Assembly Cache Viewer (shfusion.dll) is a shell extension for GAC that is installed with the .NET Framework SDK „ .NET Framework Configuration Tool (mscorcfg.msc) Š Assembly must have a strong name AsseAssembliesmblies Strong Names

Š Strong names identify an assembly

„ Contains text name, version, culture, public key, and digital signature

„ Digital Signature = E_private(Assembly Hash) Š Generated from an assembly using a private key Š Benefits

„ Guarantees name uniqueness

„ Protect version lineage z No one else can create a new version of your assembly

„ Provides strong integrity check z Guarantees that contents of an assembly didn ’ t change since it was built

Assemblies Strong Names

Š To sign an assembly with a strong name:

„ Use Strong Name tool: sn.exe

„ Use assembly attributes [AssemblyKeyFileAttribute(“key.snk”)]

„ Requires a key pair (private and public)

„ To generate a key pair use the Strong Name tool: sn.exe –k key.snk AsseAssembliesmblies Demo: Installing an Assembly in GAC

Š Create assembly Š Sign assembly with key from sn.exe Š Install into GAC via gacutil.exe, Assembly Cache Viewer and .NET Framework Configuration Tool

Assemblies Demo: Adding Resources to your assembly

Š Using Visual Studio 2008