, ebook O'Reilly Dot.Net Framework Essentials, 1st Edition 

[ Pobierz całość w formacie PDF ]
.In COM, you must store activation and marshaling[2] information in the registry for components tointeroperate; as a result, any COM developer can discuss at length the pain and suffering inherent inCOM and the system registry.In.NET, the system registry is no longer necessary for componentintegration.[2]Distributed application requires a communication layer to assemble and disassemble application data and network streams.Thislayer is formally known as a marshaler in Microsoft terminology.Assembling and disassembling an application-level protocol networkbuffer are formally known as marshaling and unmarshaling, respectively.In the.NET environment, components can be private , meaning that they are unpublished and used byknown clients, or shared, meaning that they are published and used by all clients.This sectiondiscusses several options for deploying private and shared components.4.1.1 Private ComponentsIf you have private components that are used only by specific clients, you have two deploymentoptions.You can store the private components and the clients that use these components in the samedirectory, or you can store the components in a specific directory that the client can access.Sincethese clients use the exact private components that they referenced at build time, the CLR doesn'tsupport version checking or enforce version policies on private components.To install your applications in either of these cases, perform a simple xcopy of your application filesfrom the source installation directory to the destination directory.When you want to remove theapplication, remove these directories.You don't have to write code to store information into theregistry, so there's no worrying about whether you've missed inserting a registry setting for correctapplication execution.In addition, because nothing is stored in the registry, you don't have to worryabout registry residues.4.1.1.1 One-directory deploymentTo specify component location in the same directory as the client application, use the following syntax(as we did in a Chapter 3 example):csc /r:vehicle.dll;car.dll;plane.dll /t:exe /out:drive.exe drive.cs61 The reference to plane.dll does not include a directory path; therefore, the C# compiler stores thisreference as is into the client application's assembly manife st so that the CLR can resolve thisreference at runtime (i.e., find and load plane.dll and activate the Plane class).If you move any of theDLLs to a different directory, you will get an exception when you execute drive.exe.4.1.1.2 Multiple-directory deploymentInstead of storing all components in the same directory as your client application, you can also usemultiple, private paths to segregate your components to be easier to find and manage.For example,we will separate the vehicle, car, and plane components into their own private directories, as shown inFigure 4-1.We will leave the drive.exe application in the top directory, MultiDirectories.Figure 4-1.Multiple -directory tree of componentsWhen you build the vehicle component, you don't have to do anything special, as it doesn't referenceor use any th ird-party components.However, when you build the car or plane component, you mustrefer to the correct vehicle component (i.e., the one in the vehicle directory).For example, to build theplane component successfully, you must explicitly refer to vehicle.dll using a specific or relative path,as shown in the following command (cd to the plane directory):csc /r:.\vehicle\vehicle.dll /t:library /out:plane.dll plane.csYou can build the car component the same way you build the plane component.To compile your clientapplication, you must also refer to your dependencies using the correct paths (cd to the main directory,MultiDirectories, before you type this command all on one line):csc /r:vehicle\vehicle.dll;car\car.dll;plane\plane.dll/t:exe /out:drive.exe drive.csWhen you execute this command, the C# compiler records these referenced private paths into yourapplication's assembly manifest.When you execute drive.exe, the CLR looks into your application'sassembly manifest to find and load the targ et components.4.1.2 Shared ComponentsUnlike application-private assemblies, shared assemblies ones that can be used by any clientapplication must be published or registered in the system Global Assembly Cache (GAC).When youregister your assemblies ag ainst the GAC, they act as system components, such as a system DLL thatevery process in the system can use.A prerequisite for GAC registration is that the component mustpossess originator and version information.In addition to other metadata, these two items allowmultiple versions of the same component to be registered and executed on the same machine.Again,unlike COM, we don't have to store any information in the system registry for clients to use theseshared assemblies.There are three general steps to registering your shared assemblies against the GAC:1.Use the shared named (sn.exe) utility to obtain a public/private key pair.This utility generatesa random key pair for you and saves the key information in an output file for example,originator.key.2.Build your assembly with an assembly version number and the key information fromoriginator.key.3.Use the.NET Global Assembly Cache Utility (gactutil.exe ) to register your assembly in theGAC.This assembly is now a shared assembly and can be used by any client.62 .NET Framework EssentialsThe commands that we use in this section refer to relative paths, so if you're following along, makesure that you create the directory structure as shown in Figure 4-2.The vehicle, plane, and cardirectories hold their appropriate assemblies, and the key directory holds the public/private key pairthat we will generate in a moment.The car -build directory holds a car assembly with a modified buildnumber, and the car -revision directory holds a car assembly with a modified revision number.Figure 4-2.Directory structure for examples in this section4.1.2.1 Generating a random key pairWe will perform the first step once and reuse the key pair for all shared assemblies that we build in thissection.We're doing this for brevity because you can use different key information for each assembly,or even each version, that you build [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • anikol.xlx.pl