Managing assemblies
Posted on 20 Mar 2006 at 12:18
Thomas Lee delves deeper into the world of .NET assemblies and their deployment management in the enterprise
This approach allows developers to provide just the public key to the compiler(s) and switch off the detailed key checking during testing. Once each assembly is fully tested, a trusted administrator with access to the private key can sign them all. Typically, this would be done as part of the development organisation's release cycle. For more information on the al.exe and sn.exe commands, see the online SDK at msdn.microsoft.com or tinyurl.com
If you're an administrator managing the use of .NET applications, you're probably not going to be doing much signing or checking of signatures - for the IT pro, such low-level stuff is all pretty much taken care of by the developer. However, in order to make use of the Global Assembly cache, all the assemblies you manage must have strong names, so it's important to understand the basics of how this all works.
To illustrate this, I'm going to show you a simple client application that calls an external, strongly named DLL. Here's the client program:
using System;
public class client
{
public static void Main()
{Console.WriteLine("In Maths Client");
Maths m = new Maths ();
long r1 = 2;
long r2 = 2;
long r = m.Add(r1, r2);
Console.WriteLine ("2 + 2 = {0}", r.ToString() );
}
}
This application calls an externally defined class called Maths to perform simple addition. When you compile this application, you reference the assembly containing this class, and the compiler does the rest.
The external class, which at runtime is found in a separate DLL, looks like this:
using System;
using System.Reflection;
[assembly:AssemblyVersion("1.1.1.100")]
[assembly:AssemblyCulture("")]
public class Maths
{
public long Add(long a, long b)
{
Console.WriteLine("In Strongly Named Maths2.dll");
return a + b;
}
}
As you can see, the external class specifies its version number and culture using attributes, plus the key file to use as part of the compilation process. To compile these two bits of code using the built-in compilers, and then run the client application, the commands would look something like:
C:\PCPro>csc /t:library maths2.cs
C:\PCPro>csc /r:maths2.dll client.cs
C:\PCPro>client
In Maths Client
In Strongly Named Maths2.dll
2 + 2 = 4
C:\PCPro>
The strongly named assembly in this case resides in the same folder as the client executable. The simplest method of deploying this application and its supporting DLL would be to place them both in their own separate folder, independent of any other applications with the same name. To see the strong name created by the compilation of the maths2.sll, use ILDASM to view the assembly's manifest, where you can see the strong name, public key and version numbers of this assembly. If you were to use ILDASM to examine the manifest of client.exe, you'd see an external reference for maths.dll, and this reference would include the public key and the version number.
Global Assembly Cache
When you install the .NET Framework onto a PC, the installer creates a machine-wide assembly cache known as the Global Assembly Cache (GAC). You can use the GAC to store assemblies that are used by multiple applications, and a key requirement for any assembly you wish to place in the GAC is that it must have a strong name.
From around the web
advertisement
- Why virtualisation hasn't slowed the growth of data
- How to make Google AdWords work for your business
- The curse of sloppily written software
- Paying for your crimes with Bitcoin
- Behind the scenes: tech support for Formula 1
- The security risk of fat fingers
- Why Windows Phone 7 isn't quite ready for business
- When will Microsoft stop fiddling with Windows 8?
- Flash down the pan?
- Metro Style apps vs desktop applications
- Chrome's shine getting lost in translation
- BytePac: the cardboard hard disk enclosure
- How tech loosens our grip on reality
- Hokum watch: Safer Internet Day
- Why I'm deleting Adobe from my PC
- Prepare to be patronised: it's Safer Internet Day
- Dear Sony, Samsung and every other tech company in the world: stop trying to be Apple
- Will Apple's Final Cut Pro X update placate the pros?
- Smartr Contacts for iPhone review
- Switching to Office 365's Outlook Web App
- VeriSign slammed for security breach cover-up
- SAP willing to share HANA with Oracle
- Why using a tablet could harm your health
- New RIM boss: no need for drastic change
- RIM founders fall on their swords
- Slow economy helps boost Red Hat revenue by 23%
- Google+ pages get multiple admins
- One in five companies lack card industry compliance
- Oil industry warns hacking attacks could kill
- British workers fear email monitoring
advertisement

