understanding code compilation and deployment lesson 4

24
Understanding Code Compilation and Deployment Lesson 4

Upload: edwin-harris

Post on 27-Dec-2015

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Understanding Code Compilation and Deployment Lesson 4

Understanding Code Compilation and Deployment

Lesson 4

Page 2: Understanding Code Compilation and Deployment Lesson 4

Objective Domain Matrix

Skills/Concepts MTA Exam Objectives

Understanding Code Compilation

Understand the fundamentals of Microsoft Intermediate Language (MSIL) and Common Language Infrastructure (CLI) (3.1)

Understanding Assemblies and Metadata

Understand the use of strong naming (3.2)

Understanding Assemblies and Metadata

Understand assemblies and metadata (3.4)

Understanding Code Deployment

Understand version control (3.3)

Page 3: Understanding Code Compilation and Deployment Lesson 4

Understanding Code Compilation

• Code written in high-level programming language must be translated to the machine language before it can be executed.• Traditional compilation model:

Page 4: Understanding Code Compilation and Deployment Lesson 4

.NET Compilation Model

• In the .NET Framework, compilation is a two-step process:

• CIL: Common Intermediate Language• The Common Language Runtime (CLR) uses Just-in-Time (JIT)

compilation to convert the CIL code into machine code.

Page 5: Understanding Code Compilation and Deployment Lesson 4

Common Language Infrastructure (CLI)

• CLI is an international standard that provides the specifications for the executable code and the runtime environment in which the code runs.• CLI makes it easier to write components and applications in any

language.• The Common Language Runtime (CLR) is Microsoft’s implementation

of the CLI.

Page 6: Understanding Code Compilation and Deployment Lesson 4

CLI Specifications - 1

• Common Type System (CTS) – Specifies rules that allows for objects written in one language to be used by objects written in another language as if they were written in the same language. • Common Language Specification (CLS) – Specifies rules that a

language must comply with in order to interoperate with other CLS-compliant programming languages.

Page 7: Understanding Code Compilation and Deployment Lesson 4

CLI Specifications - 2

• Metadata - A structured way to represent information about a program structure that the CLI uses to locate and load classes at runtime. • Virtual Execution System (VES) - Specifies how the runtime loads and

executes CLI-compatible programs.

Page 8: Understanding Code Compilation and Deployment Lesson 4

Language Interoperability

• Language interoperability means that code written in one programming language can be fully used by code written in a different programming language.• CLS specifies a set of rules that enables the code written in a

programming language to interoperate with the code written in other programming languages on the .NET Framework.

Page 9: Understanding Code Compilation and Deployment Lesson 4

Assembly

• An assembly is a collection of types and resources that is built to work together to form a logical unit of functionality. • Assemblies are the fundamental unit of deployment, version control,

and security in the .NET Framework.• The output from .NET language compiler (a .dll file or an .exe file) is

bundled into an assembly.

Page 10: Understanding Code Compilation and Deployment Lesson 4

Assembly Structure

• An assembly contains the following four pieces of information:• Assembly manifest contains information such as version and identity of the

assembly.• Metadata related to the classes contained in the assembly• CIL code that implements the classes• A set of resources (such as .bmp file or a .jpg file) used by the classes.

Page 11: Understanding Code Compilation and Deployment Lesson 4

Assembly Metadata

• Metadata is the data that describes the types defined by the code and the external types used by the code. • Metadata has complete information about the structure of a type

and its members.• Metadata is independent of any particular programming language

and is stored along with the CIL as part of an assembly.

Page 12: Understanding Code Compilation and Deployment Lesson 4

IL Disassembler (ildasm.exe)

• Allows you to view the contents of an assembly like the manifest, metadata and the CIL.

Page 13: Understanding Code Compilation and Deployment Lesson 4

Assembly Deployment

• Assemblies can be deployed as:• Private assemblies• Shared assemblies

• A private assembly is designed to be used by only a single application.• A shared assembly is designed to be used by multiple applications.

Page 14: Understanding Code Compilation and Deployment Lesson 4

Private Assemblies

• A private assembly is local to the application that uses it and is deployed within the application’s directory structure.• Any changes to a private assembly cannot possibly affect any other

installed application on the same machine.• The .NET Framework does not impose any special versioning or

naming requirements for a private assembly.

Page 15: Understanding Code Compilation and Deployment Lesson 4

Shared Assemblies

• The shared assemblies are all installed at a common, well-known location on the file system known as the Global Assembly Cache (GAC).• The .NET Framework allows multiple versions of a shared assembly to

coexist.• A shared assembly must have an associated strong name.

Page 16: Understanding Code Compilation and Deployment Lesson 4

Strong Naming

• Strong name specifies an assembly’s unique identity. • Strong name uses four attributes to identify an assembly:

• Simple name• Version number• Culture identity (optional)• Public key token

Page 17: Understanding Code Compilation and Deployment Lesson 4

Strong Name Tool

• The Strong Name tool helps sign assemblies with strong names. • The strong name tool is used to generate keys used for creating

strong names.

Page 18: Understanding Code Compilation and Deployment Lesson 4

Signing the Assembly

• The Signing tab in the Visual Studio project’s properties dialog box allows you to assign a strong name to the assembly.

Page 19: Understanding Code Compilation and Deployment Lesson 4

Assembly Information

• The Assembly Information dialog box allows you to specify version and other information.

Page 20: Understanding Code Compilation and Deployment Lesson 4

Global Assembly Cache

• The Global Assembly Cache (GAC) is the central repository for storing shared assemblies on a computer. • Ways to add an assembly to the GAC:

• Windows Installer: Recommended approach for installing assemblies on the end user’s computer.• Global Assembly Cache tool (gacutil.exe): Recommended only for

development and testing.

Page 21: Understanding Code Compilation and Deployment Lesson 4

Global Assembly Cache Benefits

• Integrity check: This check guarantees that the contents of the assembly have not been changed since it was built.• Security: Only users with administrator privileges can modify GAC

contents.• Side-by-side versioning: Multiple assemblies with the same name

but different version numbers can be maintained in the GAC.

Page 22: Understanding Code Compilation and Deployment Lesson 4

Using the Global Assembly Cache Tool

• Install assembly to the GAC• gacutil /i assemblyFileName

• Uninstall assembly from GAC• gacutil /u assemblyName

• List all versions of an assembly from GAC• gacutil /l assemblyName

Page 23: Understanding Code Compilation and Deployment Lesson 4

Assembly Versioning

• Side-by-side execution: Some applications still use the old version of the assembly while other applications use the new version.• Publisher Policy (bug-fix update): All applications that reference the

defective version of the assembly to start using the new version—and preferably without any modifications to the already installed applications.

Page 24: Understanding Code Compilation and Deployment Lesson 4

Recap

• Understanding code compilation• .NET Compilation Model• Common Language Infrastructure (CLI)• Language interoperability• Assembly

• Assembly Metadata• IL Disassembler• Private Assembly

• Shared Assembly• Strong Name• Strong Name Tool• Global Assembly cache• Global Assembly Cache Tool (gacutil.exe)• Version control