240 likes | 405 Views
Understanding Code Compilation and Deployment. Lesson 4. Objective Domain Matrix. 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:. .NET Compilation Model.
E N D
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:
.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.
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.
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.
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.
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.
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.
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.
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.
IL Disassembler (ildasm.exe) • Allows you to view the contents of an assembly like the manifest, metadata and the CIL.
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.
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.
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.
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
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.
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.
Assembly Information • The Assembly Information dialog box allows you to specify version and other information.
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.
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.
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
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.
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