Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

C# ПІДРУЧНИКИ / c# / MS Press - Msdn Training Programming Net Framework With C#

.pdf
Скачиваний:
173
Добавлен:
12.02.2016
Размер:
16.87 Mб
Скачать

Module 4: Deployment and Versioning

37

 

 

 

Lab 4: Packaging and Deployment

Topic Objective

To introduce the lab.

Lead-in

In this lab, you will build an application that is named client, which retrieves an array of strings from an instance of the Stringer class and reverses the order of these strings by using an instance of the AReverser class. These classes are packaged in two separate assembly libraries that are named Stringer.dll and AReverser.dll.

*****************************ILLEGAL FOR NON-TRAINER USE******************************

Objectives

After completing this lab, you will be able to:

!Create an application by using private assemblies in multiple directories.

!Install and remove a strong-named assembly from the global assembly cache.

!Configure an application to control its binding to an assembly based on the assembly’s location and version data.

Lab Setup

Starter and solution files are associated with this lab. The starter files are in the folder <install folder>\Labs\Lab04\Starter. The solution files are in the folder <install folder>\Labs\Lab04\Solution.

Scenario

You will build an application that is named client, which retrieves an array of strings from an instance of the Stringer class and reverses the order of these strings by using an instance of the AReverser class. These classes are packaged in two separate assembly libraries that are named Stringer.dll and AReverser.dll.

Estimated time to complete this lab: 50 minutes

38

Module 4: Deployment and Versioning

Exercise 1

Locating Private Assemblies in Multiple Directories

In this exercise, you will build the client application by using private assemblies that are located in multiple directories.

!Examine the application

Open Notepad and examine the source code for the files that are listed in the following table.

Filename

Directory location

 

 

Client.cs

<install folder>\Labs\Lab04\Starter\Compapp

Stringer.cs

<install folder>\Labs\Lab04\Starter\Compapp\MyStringer

AReverser.cs

<install folder>\Labs\Lab04\Starter\Compapp\AReverser

! Compile and build the application in a command window

Important To use Microsoft Visual Studio .NET tools within a command prompt window, the command prompt window must have the proper environment settings. The Visual Studio .NET Command Prompt window provides such an environment. To run a Visual Studio .NET Command Prompt window, click Start, All Programs, Microsoft Visual Studio .NET,

Visual Studio .NET Tools, and Visual Studio .NET Command Prompt.

1.Go to the MyStringer directory and build the private assembly library named Stringer.dll in that directory.

2.Go to the AReverser directory and make the private assembly named AReverser.dll in that directory.

3.Go to the Compapp directory and build the client application, referencing the private assemblies from steps 1 and 2. Reference the DLLs in their own directories. Do not copy them to the Compapp directory.

Module 4: Deployment and Versioning

39

 

 

 

! Execute the application

1.Run the Assembly Binding Log Viewer by executing Fuslogvw.exe. Click on the right hand check box labeled Log Failures.

2.Execute the Client.exe application and note the exception in the space that is provided.

3.In the Assembly Binding Log Viewer click on Refresh. Then double click on the Client.exe application, and view the log entry.

4.Create a configuration file in the Client directory to specify the appropriate privatePath so that the application can successfully bind and load the necessary classes.

The Client.exe application should generate the following output:

Strings from StringComponent

C# String 0

C# String 1

C# String 2

C# String 3

Reversed Array Strings

C# String 3

C# String 2

C# String 1

C# String 0

40

Module 4: Deployment and Versioning

Exercise 2

Using Strong-Named Assemblies and Versioning

In this exercise, you will build the client application by using strong-named assemblies that are located in the global assembly cache. You will then configure an application to control its binding to an assembly based on the assembly’s location and version data.

!Build a compatible strong-named version of AReverser

1.From a command prompt window, navigate to the <install folder>\Labs\ Lab04\Starter\Compapp directory, and use the Strong Name tool to create a public-private key pair file that is named OrgVerKey.snk.

2.Open Notepad. On the File menu, click Open, browse to <install folder>\ Labs\Lab04\Starter\ Compapp\AReverser_v2.0.0.0, and open AReverser.cs.

3.Examine the source code and note that it is the same code that was used in the preceding exercise.

In particular, note that the signature of the Invert method is:

public string[] Invert(string[] myString)

4.Modify the source code to specify the key pair file from step 1 and to specify a version number of 2.0.0.0.

5.From a command prompt window, navigate to the <install folder>\Labs\ Lab04\Starter\Compapp directory and build the 2.0.0.0 strong-named version of AReverser.cs. The AReverser.dll should be output into the AReverser_v2.0.0.0 subdirectory.

6.Use the global assembly cache tool (Gacutil.exe) to install this assembly in the global assembly cache.

7.Examine the global assembly cache by using Gacutil.exe or Windows Explorer, and note the presence of AReverser and its properties.

!Build an incompatible strong-named version of AReverser

1.In Notepad, on the File menu, click Open, browse to <install folder>\ Labs\Lab04\Starter\Compapp\AReverser_v2.0.1.0, and open AReverser.cs.

2.Examine the source code and note that it is different than the code that was used in the preceding exercise.

In particular, note that the signature of the Invert method is:

public string[] Invert(string[] myString, int myCount)

3.Modify the source code to specify the key pair file OrgVerKey.snk and to specify a version number of 2.0.1.0.

4.From a command prompt window, navigate to the <install folder>\Labs\ Lab04\Starter\Compapp directory and build the 2.0.1.0 strong-named version of AReverser.cs. The AReverser.dll should be output into the AReverser_v2.0.1.0 subdirectory.

5.Install this assembly in the global assembly cache.

6.Examine the global assembly cache by using Gacutil.exe or Windows Explorer, and note the presence of AReverser and its properties.

Module 4: Deployment and Versioning

41

 

 

 

! Compile, build, and execute the application

1.From a command prompt window, navigate to the Client directory and build the client application. Reference the private assembly MyStringer\Stringer.dll and the strong-named assembly AReverser_v2.0.0.0\AReverser.dll.

2.Execute the Client.exe application, which should generate the following output:

Strings from StringComponent

C# String 0

C# String 1

C# String 2

C# String 3

Reversed Array Strings

C# String 3

C# String 2

C# String 1

C# String 0

! Configure to bind to the latest version of AReverser

Tip You can obtain the publicKeyToken tag’s value by examining the global assembly cache using gacutil /l or the cache shell extension.

1.Modify the configuration file to bind to the incompatible later version 2.0.1.0 of AReverser.

2.Execute Client.exe and note the exception.

3.Use the global assembly cache tool to remove the two strong-named versions of AReverser.

4.Confirm the removal of the two strong-named versions of AReverser by viewing the global assembly cache with Gacutil.exe and Windows Explorer.

42

Module 4: Deployment and Versioning

Review

Topic Objective

To reinforce module objectives by reviewing key points.

Lead-in

The review questions cover some of the key concepts taught in the module.

!Introduction to Application Deployment

!Application Deployment Scenarios

!Related Topics and Tools

*****************************ILLEGAL FOR NON-TRAINER USE******************************

1.What part of the assembly identifies its imported and exported types and its version information?

The manifest.

2.What software does a computer require to run a .NET application locally?

The .NET Framework common language runtime.

3.Name two simple ways to run a .NET Framework application.

Copy the executable file and referenced assemblies to the local computer, or access them on a file server.

Module 4: Deployment and Versioning

43

 

 

 

4.Describe how an application can use an assembly that is located in an application’s subdirectory.

Create a configuration file in the application’s directory that specifies a PrivatePath as follows:

<configuration>

<runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="MyStringer"/>

</assemblyBinding>

</runtime>

</configuration>

5.What kind of assembly can be placed in the global assembly cache and be versioned?

A strong-named assembly.

6.What command is used to generate public-private key pairs?

The Strong Name (Sn.exe) tool is used to generate a new key pair and place them in a file:

sn –k orgKey.snk

7.What command is used to install a strong-named assembly into the global assembly cache?

> gacutil -i <filename>

Module 5: Common

Type System

Contents

 

Overview

1

An Introduction to the Common Type

 

System

2

Elements of the Common Type System

8

Object-Oriented Characteristics

25

Lab 5: Building Simple Types

39

Review

44

Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

2001-2002 Microsoft Corporation. All rights reserved.

Microsoft, ActiveX, BizTalk, IntelliMirror, Jscript, MSDN, MS-DOS, MSN, PowerPoint, Visual Basic, Visual C++, Visual C#, Visual Studio, Win32, Windows, Windows Media, and

Window NT are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries.

The names of actual companies and products mentioned herein may be the trademarks of their respective owners.

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