Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C# ПІДРУЧНИКИ / c# / Hungry Minds - Visual C# Blueprint.pdf
Скачиваний:
101
Добавлен:
12.02.2016
Размер:
9.71 Mб
Скачать

C#

VERSION A SHARED ASSEMBLY

ou can version assemblies if you use shared Yassemblies. Versioning helps the CLR determine

which physical class to load when an object request is made from a client application. Versioning of the same component enables you to manage distributing updates to applications without breaking clients.

You build version numbers from four sets of numbers that you separate by periods: Major, Minor, Revision, and Build Number. You configure the version number in the AssemblyVersion assembly-level attribute that you find in the AssemblyInfo file. To do so, you need to understand the compatibility between the two versions of the same component.

The numbered steps below enable you to create two versions of the same shared component. After you register each version, you see two rows for the component in the GAC, one for each version. Both lines look identical, except for the version number (one being 1.0.0.0 and the other being 2.0.0.0). Versioning in .NET allows for side-by-side execution of the same component, which gives the capability to have an instance of each version running at the same time on the same machine, which is a useful, new capability of the .NET platform.

VERSION A SHARED ASSEMBLY

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Create two directories for

 

Á Open the

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Change the

 

 

 

 

 

 

 

 

 

 

 

 

versions of the

AssemblyInfo.cs file.

 

AssemblyVersion to a

 

 

 

.

 

 

 

 

 

 

later version number.

 

 

 

 

 

 

 

 

the component into

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

earlier version directory.

 

 

 

 

 

 

 

CREATING AND DEPLOYING DISTRIBUTED APPLICATIONS 14

You can determine different compatibility scenarios with the four sets of numbers that make up a version:

Incompatible — Change to the assembly making it incompatible with previous versions. Two versions are incompatible when the Major and Minor numbers between the two versions do not match.

Maybe Compatible — Change to the assembly that is thought to be compatible and carries less risk than an incompatible change. However, backward compatibility is not guaranteed. An example is a service pack or a release of a new daily build.

QFE (Quick Fix Engineering) — Engineering fix that customers must upgrade. An example is an emergency security fix. Does not impact compatibility.

If you install a new version of a shared component on your clients machine, the runtime determines if it can use the new version for calls from existing clients. For example, if you compile a client against a shared component with version 2.1.1.101, and then install a new version at a later date that has version 2.1.1.211, the client application uses the newer version 2.1.1.211 the next time it makes a request to load the assembly.

° Open the Photo.cs file. · Change the message to display the later version number.

Build the component.

Open File Explorer and navigate to the bin\Debug directory.

± Copy the component to the directory for the later version of the component.

267

C#

CONFIGURE A CLIENT FOR A VERSIONED ASSEMBLY

ou can utilize versioned assemblies to give your client Yapplications an upgrade path for newer, optimized or

enhanced components. With the versioning capabilities of .NET, you can use an assembly that has extended its members without the need to recompile. The version binding policy determines which version you need to use for a calling client to a shared assembly. The .NET runtime and/or the configuration file for the application determines what your client’s version binding policy is. The configuration file can override the .NET runtime binding by setting the versioning in the <bindingRedirect> element of the <runtime> element.

The process of using a versioned assembly is not any different than what you do with an unversioned shared assembly. You just need to make sure that you select the correct version. Shared assemblies with multiple versions will have multiple entries with the same Global Assembly Name, but each entry for that Global Assembly Name will have a different number in the version column. For more information on shared assemblies, see page 260. To check that you have the right version, after you have made the reference, you can view the properties of the reference in the reference list in the project solution.

CONFIGURE A CLIENT FOR A VERSIONED ASSEMBLY

Accessibility

1.0.0.0

C:\WINNT\Microsoft.NET\Fra...

The Add Reference dialog

Click Browse.

box appears.

 

CREATING AND DEPLOYING DISTRIBUTED APPLICATIONS 14

To control the binding of a client to a versioned assembly that your client application uses, you can create a configuration file. The example shows how to use the configuration file to redirect the binding from one version to another version. For you to test the example with the code that is created in the numbered steps below, you will have to update the publicKeyToken to match the hash of the public key that you created on page 260.

EXAMPLE:

<configuration>

<runtime>

<assemblyBinding

xmlns="urn:schemas-microsoft- com:asm.v1">

<dependentAssembly>

<assemblyIdentity name= "VersionedPhotoAlbum"

publicKeyToken=

"e79f3eb79bb2bf0a"

culture=""/>

<bindingRedirect oldVersion= "1.0.0.0"

newVersion="2.0.0.0"/>

</dependentAssembly>

</assemblyBinding>

</runtime>

</configuration>

The Select Component dialog box appears.

ˇ Go to the later version of the server component.

Á Click the component.

Click Open.

° Click OK.

· Press F5 to save, build, and run the console application.

Open the command prompt and navigate to the directory where the client was created.

Run the client application.

A message appears showing the properties set for the file and the correct version number.

269

Соседние файлы в папке c#