Working with Display Names


Working with Display Names

Figure 12.5 shows an example of a display name . Display names are strings that can be used to identify assemblies. They have four parts .

Figure 12.5 This is also known as a fully qualified display name as you will learn later in the chapter. Notice that it has four parts, separated by commas.
 SoapSudsCode, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 

The first part is the name of the DLL or EXE minus the extension. So if the DLL is named ChildCare.DLL, the first part of the display name is ChildCare.

The second part is the version number. The version number is a string in the form "version=1.2.3.4." Version numbers in .NET have four elements: major, minor, build, and revision. Major and minor numbers are the ones that people normally use to refer to a software version, "Tools version 1.5," for example. Build numbers and revision numbers are normally used for internal purposes.

When a company is working on the next version of their software, they might refer to the version as 1.5, but every time someone fixes a major bug, they rebuild the code and assign a different build number to the latest code. In this way when the boss comes around and says, "I thought you were going to fix that major bug we had," you can say, "Oh, it should be there in the latest build. Do you have build number 245?" The last number is for when you have to build multiple times on the same day, or when something minor is changed and you don't really want to do a full build of all the source code. The rule of thumb is that if you change major functionality in the software you should change at least the major or the minor numbers. The other two numbers can be used at your discretion.

The third part of the display name is the culture. The culture is written in the form "Culture=en_us" or "Culture=neutral". Cultures have two parts, the language, and the region in which the language is spoken. They're used in situations in which programs need to be translated into different languages. Any assembly that contains executable code has a Culture=neutral, which means it can be used from anywhere . You can also put resources into an assembly without code, like a list of strings, and then assign it a culture. Writing assemblies for resources is beyond the scope of this book; for the most part you will leave the culture as neutral.

The third part of the display name is the PublicKeyToken, which is written in the form "PublicKeyToken= a5d015c7d5a0b012." The last number is a part of the public key in a public/private encryption key. With public/private key encryption, a private key is used to encrypt information, while the public key is used to decrypt it. Only information encrypted with the private key can be decrypted with the public key.

In Chapter 13, "C# Web projects," you'll learn how to add public key tokens to an assembly. You add a public key token for two purposes: one is to prevent "bad guys" (or bad people, rather) from tampering with the assembly. The second reason is that you need to add a public key if you want to share your assembly with multiple Web applications.

Many times display names are used to refer to assemblies that are in the Global Assembly Cache (GAC). The GAC has assemblies that are shared by multiple applications. In Chapter 13 you'll learn how to add an assembly to the GAC. For now, let's see how to obtain the display name of an assembly that is in the GAC.

To build the display name for an assembly in the GAC:

  1. Using Windows Explorer, navigate to the Windows\Assembly directory ( Figure 12.6 ).

    Figure 12.6. This is assembly heaven! The GAC is really a bunch of directories under Windows\Assembly, but Microsoft installs a viewer that lets you see a nice list of assemblies if you navigate there with Windows Explorer. If you navigate there through a command prompt, you'll uncover the true nature of the GAC.

    graphics/12fig06.gif

  2. Write the assembly name from the first column followed by a comma.

  3. Write Version= followed by the value in the version column, followed by a comma.

  4. Write Culture=neutral followed by a comma.

  5. Write PublicKeyToken= followed by the value in public key token.

graphics/tick.gif Tips

  • If you right-click on an assembly in the GAC and choose properties, you'll see a dialog like the one in Figure 12.7 . From there you can copy the version number or the PublicKeyToken and paste it into your code.

    Figure 12.7. Even though you can see most of this information without getting the Properties dialog, this dialog makes it easier to select the information and copy it into your code.

    graphics/12fig07.gif

  • The order in which you write the different parts of the display string isn't important. The only part that needs to go first is the assembly name.




C#
C# & VB.NET Conversion Pocket Reference
ISBN: 0596003196
EAN: 2147483647
Year: 2003
Pages: 198
Authors: Jose Mojica

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net