32
1 Program Execution Program Execution in the 21 in the 21 st st Century Century Modern Software Development Modern Software Development in .NET and C# in .NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [ http://www.lakeforest.edu/~hummel/webcasts.htm ] [ http://www.lakeforest.edu/~hummel/webcasts.htm ] Joe Hummel, PhD Joe Hummel, PhD Software Architect, Author & Software Architect, Author & Professor Professor Barracuda.NET: Barracuda.NET: [email protected] [email protected] Lake Forest College: Lake Forest College: [email protected] [email protected]

1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

Embed Size (px)

Citation preview

Page 1: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

1

Program Execution in Program Execution in the 21the 21stst Century CenturyModern Software Development in .NET Modern Software Development in .NET and C#and C#A webcast series for C++, Java, and VB6 developers – Part 1 of A webcast series for C++, Java, and VB6 developers – Part 1 of 15:15: [ http://www.lakeforest.edu/~hummel/webcasts.htm ] [ http://www.lakeforest.edu/~hummel/webcasts.htm ]

Joe Hummel, PhDJoe Hummel, PhDSoftware Architect, Author & ProfessorSoftware Architect, Author & ProfessorBarracuda.NET:Barracuda.NET: [email protected]@Barracuda.netLake Forest College: Lake Forest College: [email protected]@lakeforest.edu

Page 2: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

2

"Modern Software Dev in .NET "Modern Software Dev in .NET and C#"and C#"

A series for C++, Java, and VB6 A series for C++, Java, and VB6 developersdevelopers

PPT-based lecturesPPT-based lectures

Lab exercises — i.e. homework!Lab exercises — i.e. homework!DateDate TopicTopic

1. Tues, March 1. Tues, March 11

Program Exec in the 21Program Exec in the 21stst CenturyCentury

2. Tues, March 2. Tues, March 1515

Classes, Components & Classes, Components & NamespacesNamespaces

3. Tues, March 3. Tues, March 2222

Modern OO Programming in C#Modern OO Programming in C#

4. Tues, March 4. Tues, March 2929

Class Design for the .NET Class Design for the .NET FrameworkFramework

.. ..

.. ..

.. ..15. Tues, June 15. Tues, June 28 28

The Microsoft .NET Team The Microsoft .NET Team SystemSystem

Page 3: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

3

Session PrerequisitesSession Prerequisites

This is an This is an introintro of how .NET executes an of how .NET executes an appapp

Prereqs:Prereqs:developer developer

object-based programming experience object-based programming experience

Level 200Level 200

Page 4: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

4

Today's objectivesToday's objectives

““The days of compiling and linking a program to produce a The days of compiling and linking a program to produce a single native executable (.EXE) are coming to an end. single native executable (.EXE) are coming to an end. While program execution in WindowsWhile program execution in Windows®® has long been has long been DLL-based (dynamic linking), with .NET we are moving DLL-based (dynamic linking), with .NET we are moving towards a virtual machine model of execution…towards a virtual machine model of execution…””

Topics:Topics:Managed ExecutionManaged Execution

Component-Based DesignComponent-Based Design

Deployment Deployment

Page 5: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

5

AgendaAgenda

Managed ExecutionManaged Execution

Component-Based DesignComponent-Based Design

Assembly ResolutionAssembly Resolution

DeploymentDeployment

Page 6: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

6

Managed ExecutionManaged Execution

Idea:Idea:modern software executes within run-time modern software executes within run-time environmentenvironment

why? portable and safer execution…why? portable and safer execution…

HardwareHardware

Operating SystemOperating System

Run-time EnvironmentRun-time Environment

Your ApplicationYour Application

Page 7: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

7

JavaJava

Based on run-time environment called Based on run-time environment called JVMJVM

JVM = Java Virtual MachineJVM = Java Virtual MachineJCL = Java Class LibraryJCL = Java Class Library

x86x86

WindowsWindows

JVMJVM

PPCPPC

Mac OSMac OS

JVMJVM

ARMARM

Palm OSPalm OS

JVMJVM

Java ApplicationJava Application

……

……

JVMJVM

JCLJCL

Page 8: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

8

.NET.NET

Based on Based on CLRCLR and and FxCLFxCLCLR = Common Language RuntimeCLR = Common Language Runtime

FxCL = Framework Class LibraryFxCL = Framework Class Library

HardwareHardware

Operating SystemOperating System

Common Language RuntimeCommon Language Runtime

.NET Application.NET Application .NET Framework.NET FrameworkClass LibraryClass Library

Page 9: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

9

Software Development in .NETSoftware Development in .NET

Pick your language and platform…Pick your language and platform…

x86x86

WindowsWindows

CLRCLR

ARMARM

Pocket PCPocket PC

CLRCLR

PPCPPC

FreeBSDFreeBSD

CLRCLR

x86x86

LinuxLinux

CLRCLR

……

……

CLRCLR

.NET Application.NET Application FxCLFxCL

VBVB C#C# C++C++ J#J# ……

Page 10: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

10

Implications…Implications…

Your clients Your clients mustmust have the .NET have the .NET FrameworkFramework

available via available via Redistributable .NET FrameworkRedistributable .NET Framework (20MB) (20MB)

3 versions: v1.0 (2002), v1.1 (2003), v2.0 (june 3 versions: v1.0 (2002), v1.1 (2003), v2.0 (june 2005?)2005?)

Windows 2003 ships with v1.1Windows 2003 ships with v1.1

otherwise correct version must be installedotherwise correct version must be installed

Design trade-off:Design trade-off: portableportable safer execution (memory management, safer execution (memory management,

security, …)security, …) slower?slower?

Page 11: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

11

Managed code Managed code

C#, VB, J# compilers generate C#, VB, J# compilers generate managedmanaged codecode

code that requires CLR to run & managecode that requires CLR to run & manage

C++ plays a dual role:C++ plays a dual role:generates generates managedmanaged code (i.e. .NET dll/exe) code (i.e. .NET dll/exe)

generates generates unmanagedunmanaged code (i.e. native code (i.e. native dll/exe)dll/exe)

common for OS work, legacy apps, etc.common for OS work, legacy apps, etc.

Page 12: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

12

CILCIL

CIL = CIL = Common Intermediate LanguageCommon Intermediate LanguageCIL is the assembly language of the CLRCIL is the assembly language of the CLR

managed code == CIL codemanaged code == CIL code

// adds 2 integers together and returns the result…public int Add(int x, int y){ return x + y;}

C:\> ildasm app.exe

Page 13: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

13

AgendaAgenda

Managed ExecutionManaged Execution

Component-Based DesignComponent-Based Design

Assembly ResolutionAssembly Resolution

DeploymentDeployment

Page 14: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

14

Apps are Component-BasedApps are Component-Based

Apps consist of 1 or more components Apps consist of 1 or more components (DLLs)(DLLs)

Example:Example:typical n-tier designtypical n-tier design

Front-end

object object

object

DB

GUI.exeGUI.exe business.dllbusiness.dll data.dlldata.dll

Page 15: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

15

.NET is Component-Based.NET is Component-Based

CLR and FxCL are components:CLR and FxCL are components:

CLR = Common Language RuntimeFxCL = Framework Class Library

CLR (MSCOREE.dll)

CLR (MSCOREE.dll)

JIT Compiler

Process

Underlying OS and HW

Core FxCL

(MSCOR

LIB.dll)

Core FxCL

(MSCOR

LIB.dll)

.DLL.DLL.DLL.DLL.EXE.EXE

obj code

additional FxCL components (DLLs)

additional FxCL components (DLLs)

Page 16: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

16

AssembliesAssemblies

.NET components are called .NET components are called assembliesassemblies

Unit of deployment in .NETUnit of deployment in .NET1 assembly = 1 or more compiled source files1 assembly = 1 or more compiled source files

Visual Studio .NET

.EXE / .DLL.EXE / .DLL

code.vbcode.vbcode.vbcode.vb

code.cscode.cs

assembly

Page 17: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

17

Where are FxCL assemblies?Where are FxCL assemblies?

FxCL assemblies are stored in the GACFxCL assemblies are stored in the GACGAC = GAC = Global Assembly CacheGlobal Assembly Cache

LocalLocal

SharedShared

Version-awareVersion-aware

SecureSecure

Tamper-proofTamper-proof

Some pre-JITSome pre-JIT

Page 18: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

18

AgendaAgenda

Managed ExecutionManaged Execution

Component-Based DesignComponent-Based Design

Assembly ResolutionAssembly Resolution

DeploymentDeployment

Page 19: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

19

Assembly ResolutionAssembly Resolution

CLR must be able to locate correct CLR must be able to locate correct assembliesassemblies

FxCL assemblies as well as our own assembliesFxCL assemblies as well as our own assemblies

CLR CLR

JIT Compiler

Process

Core FxCL

Core FxCL

.DLL.DLL.DLL.DLL.EXE.EXE

obj code

additional FxCL components (DLLs)

additional FxCL components (DLLs)

Page 20: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

20

Executive Summary…Executive Summary…

Returning to the days of old, i.e. DOS-Returning to the days of old, i.e. DOS-likelike

.NET applies a well-known search algorithm (like .NET applies a well-known search algorithm (like a path)a path)

can customize search via .config file (like an .ini)can customize search via .config file (like an .ini)

no use of registry!no use of registry!

Page 21: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

21

Resolution AlgorithmResolution Algorithm

1.1. .NET figures out what version is needed.NET figures out what version is needed

2.2. .NET searches GAC (.NET searches GAC (Global Assembly Global Assembly CacheCache))

3.3. If not found and .config file is presentIf not found and .config file is present then .NET searches where then .NET searches where

configured toconfigured to elseelse

.NET searches directory .NET searches directory containing .EXEcontaining .EXE

4.4. If not foundIf not found then application terminates with then application terminates with errorerror

Page 22: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

22

Typical n-tier app…Typical n-tier app…

Page 23: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

23

How does .NET know version, How does .NET know version, etc.?etc.?Compiled into .DLL/.EXE as Compiled into .DLL/.EXE as manifestmanifest

use use ILDASMILDASM tool to peek inside assembly tool to peek inside assemblyILDASM = ILDASM = Intermediate Language DisassemblerIntermediate Language Disassemblermanifest reveals dependencies, versions, etc.manifest reveals dependencies, versions, etc.

C:\> ildasm CustomerGUI.exe

Page 24: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

24

Observations…Observations…

Manifest contains Manifest contains referencereference to assembly to assemblyname, version #, hash of public key token, etc.name, version #, hash of public key token, etc.

Manifest does Manifest does notnot contain: contain:code for assemblycode for assembly

registry information (no more GUIDs!)registry information (no more GUIDs!)

location information (.NET uses search path)location information (.NET uses search path)

Page 25: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

25

ImplicationsImplications

No more registry!No more registry!.NET uses well-defined search path.NET uses well-defined search path

No more DLL hell!No more DLL hell!applications never use the wrong versionapplications never use the wrong version

unless you say so via .config fileunless you say so via .config file

Config file hell?Config file hell?machine config, user config, app config, etc.machine config, user config, app config, etc.

Page 26: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

26

How are assemblies referenced?How are assemblies referenced?

Tracked via Tracked via ReferencesReferences folder in VS folder in VS projectproject

You can add more:You can add more:

Page 27: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

27

AgendaAgenda

Managed ExecutionManaged Execution

Component-Based DesignComponent-Based Design

Assembly ResolutionAssembly Resolution

DeploymentDeployment

Page 28: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

28

Deployment OptionsDeployment Options

1.1. Install assemblies in same dir as .EXEInstall assemblies in same dir as .EXE simplest, called simplest, called xcopyxcopy deployment deployment

2.2. Install some in .EXE dir, remainder in Install some in .EXE dir, remainder in GACGAC

GAC allows you to share, install multiple GAC allows you to share, install multiple versionsversions

3.3. Custom deployment via .config fileCustom deployment via .config file allows custom location, e.g. on a serverallows custom location, e.g. on a server

4.4. "Zero-touch" deployment"Zero-touch" deployment clients install via URL: clients install via URL:

http://server/app/app.exe app can update itself periodicallyapp can update itself periodically improved improved ClickOnceClickOnce coming in VS 2005 coming in VS 2005

Page 29: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

29

Lots of deploymet details…Lots of deploymet details…

How do you write .config files?How do you write .config files?

How do you put something in the GAC? How do you put something in the GAC?

Assign a version number?Assign a version number?

Make an assembly tamper-proof?Make an assembly tamper-proof?

Topics for webcast #11:Topics for webcast #11:Tues, 31 May 2005 Tues, 31 May 2005

Page 30: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

30

That’s it for today!That’s it for today!

Thank you for participatingThank you for participating

Next webcast:Next webcast:

DateDate TopicTopicTODAYTODAY Program Exec in the 21Program Exec in the 21stst Century Century

2. Tues, March 2. Tues, March 1515

Classes, Components & Classes, Components & NamespacesNamespaces

3. Tues, March 3. Tues, March 2222

Modern OO Programming in C#Modern OO Programming in C#

4. Tues, March 4. Tues, March 2929

Class Design for the .NET Class Design for the .NET FrameworkFramework

.. ..

.. ..

.. ..15. Tues, June 15. Tues, June 2828

The Microsoft .NET Team The Microsoft .NET Team SystemSystem

Page 31: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

31

Additional ResourcesAdditional Resources

Web site for slides, demos, homework:Web site for slides, demos, homework:http://http://www.lakeforest.edu/~hummel/webcasts.htmwww.lakeforest.edu/~hummel/webcasts.htm

Resources:Resources:J. Richter, "J. Richter, "Applied Microsoft .NET Framework Applied Microsoft .NET Framework ProgrammingProgramming""Rocky Lhotka, “Rocky Lhotka, “Expert C# Business ObjectsExpert C# Business Objects””Juval Löwy, “Juval Löwy, “Programming .NET ComponentsProgramming .NET Components””Zero-touch deployment:Zero-touch deployment:

http://msdn.microsoft.com/msdnmag/issues/04/05/clickonce/default.aspx

http://www.gotdotnet.com/team/windowsforms/appupdater.aspx

http://msdn.microsoft.com/msdnmag/issues/04/10/Bootstrapper/http://msdn.microsoft.com/msdnmag/issues/02/07/NetSmartClients/default.aspxhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchno-touchdeploymentinnetframework.asp

Page 32: 1 Program Execution in the 21 st Century Modern Software Development in.NET and C# A webcast series for C++, Java, and VB6 developers – Part 1 of 15: [

32