Chapter 1 IDE and Tools for Developing CLR-based Programs

Slides:



Advertisements
Similar presentations
By Sam Nasr September 28, 2004 Understanding MSIL.
Advertisements

.NET Framework Overview
Chapter 1 IDE and Tools for Developing CLR-based Programs Yingcai Xiao.
Overview of the.NET Framework. What is the.NET Framework A new computing platform designed to simplify application development A consistent object-oriented.
Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.
.NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program.
Introduction to the C# Programming Language for the VB Programmer.
Introducing the Common Language Runtime for.NET. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Introducing the Common Language Runtime. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution engine.
2. Developing in.NET and C#. 2 Microsoft Objectives “Microsoft.NET development is based on an underlying framework of tools and classes. These tools and.
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Introduction to.NET Frank McCown COMP GUI Programming Harding University.
CSC300 Visual Programming Dr. Craig Reinhart. Objectives Teach the basics of C++ –You won’t be an expert but hopefully a very good novice –GUI development.
1 8/29/05CS360 Windows Programming Professor Shereen Khoja.
Module 1: Introduction to C# Module 2: Variables and Data Types
.NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
CIS NET Applications1 Chapter 2 –.NET Component- Oriented Programming Essentials.
Introduction to .NET Framework
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Compiling and Executing Code in.Net Microsoft Intermediate Language and Common Language Runtime.
.NET Framework Overview
All 300/400 Level CS Major Courses Tutoring Location: SEC 3433 Sign up or walk-in Introduction2-1.
Introduction .NET Framework
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Introduction to.NET Frank McCown TechLunch Old Dominion University March 28, 2007.
Week 1: THE C# LANGUAGE Chapter 1: Variables and Expressions ➤ Included in Visual Studio.NET ➤ What the.NET Framework is and what it contains ➤ How.NET.
Java and C# [this is a bonus – it is not a required lesson] ACO101: Introduction to Computer Science.
Languages and IDE (Integrated Development Environment)
MSIL C#.NET Software Development. MSIL AKA CIL What all.NET languages compile to What all.NET languages compile to Binary Intermediate Language Binary.
The Execution System1. 2 Introduction Managed code and managed data qualify code or data that executes in cooperation with the execution engine The execution.
Text Introduction to.NET Framework. CONFIDENTIAL Agenda .NET Training – Purpose  What is.NET?  Why.NET?  Advantages  Architecture  Components: CLR,
Overview CNS 3260 C#.NET Software Development. 2.NET Framework Began in 2000 Developed in three years (2000 to 2003) Operating System Hardware.NET Framework.
Sung-Dong Kim Dept. of Computer Engineering, Hansung University Chapter 3 Programming Tools.
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
Computer System Structures
Building C# Applications
Introduction to .NET framework
Chapter 2: The Visual Studio .NET Development Environment
INF230 Basics in C# Programming
Introduction to .NET Framework
.NET Security and MSIL Tom Roeder CS fa.
Running Programs & IDEs Reference: COS240 Syllabus
Foundations of .Net Programming with C#
Introduction to Visual Basic 2008 Programming
Chapter 9 S. NandaGopalan, BIT
Frank McCown TechLunch Old Dominion University March 28, 2007
C# and the .NET Framework
Introduction to .NET Framework Ch2 – Deitel’s Book
CE-105 Spring 2007 Engr. Faisal ur Rehman
Application Foundation
Java programming lecture one
2.1. Compilers and Interpreters
Lecture 1: .NET What Is It And Why Use It? 9/18/2018
.NET and .NET Core 2. .NET Runtimes Pan Wuming 2017.
CS360 Windows Programming
.NET Framework: Backdoors
Module 0: Introduction Chapter 2: Getting Started
Introduction to C# AKEEL AHMED.
Programming in C# CHAPTER 1
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Lecture 1 Making a C# GUI Program
Microsoft Visual Studio
Frank McCown TechLunch Old Dominion University March 28, 2007
Computer Programming-1 CSC 111
The Role of Command Line Compiler (csc.exe)
DOT NET ARCHITECTURE (OR) DOT NET FRAME WORK ARCHITECTURE
Review of Previous Lesson
IS 135 Business Programming
Presentation transcript:

Chapter 1 IDE and Tools for Developing CLR-based Programs Yingcai Xiao

Integrated Development Environment (IDE) (1) IDE: all-in-one programming tools (2) Includes: editor, compiler, linker, loader, debugger, profiler, project organizer, context-sensitive help, form designer, programming code libraries, application framework templates, … (3) IDE you may have used: Eclipse, jGRASP, NetBeans, BlueJ (4) Microsoft IDEs: MS Visual Studio 6.0: last non .NET version. MS Visual Studio 7.0 => MS Visual Studio .NET MS Visual Studio 8.0 => MS Visual Studio .NET 2005 MS Visual Studio .NET 20xx Start->All Programs->Microsoft Visual Studio 20xx-> Microsoft Visual Studio 20xx Documentation

Create your first C# program Setup: If you are on a CS computer, refer to the following link to setup the Z drive. http://www.cs.uakron.edu/~xiao/lab-use.html Use C drive if you have problem mounting the Z drive. Remember to copy your code to a flash drive and delete your work on the C drive before logging out from the CS computer. Use C drive if you are on a home computer. In the following examples, replace drive letter Z with C if you are using the C drive.

Create your first C# program using Visual Studio .NET (1) Create a project Start->All Programs->Microsoft Visual Studio 20xx-> Microsoft Visual Studio 20xx Start Page -> New Projects Visual C#->Windows->Console Application Name: Hello Solution name: Hello Location: Browse Folders->Computer->Z->WP (New Folder) -> Select Folder (Default on winserv1: C:\users\xiaotest\documents\visual studio 20xx\Projects) OK (2) Code System.Console.WriteLine ("Hello, world!"); System.Console.WriteLine ("Hit any key to end."); System.Console.Read(); (3) Run F5 (Debug->Start Debugging) Z:\WP\Hello\bin\Debug\bin

(1) Project setting: Debugging Set project to “Debug” (default setting) DEBUG->Start Debugging (2) Break points left-click on the left frame of the source window to set a break point. (3) Watch right-click on a variable select Add to Watch (4) Windows Watch window Output window for debugging Console window for the running program

Debugging

z:\WP\Hello ( the solution directory) VS Project Directory z:\WP\Hello ( the solution directory) Hello.sln (solution info) Hello (project directory, there can be more than one project) z:\WP\Hello->Hello ( the project directory) Program.cs (the C# source file) Hello.csproj (C# project info) App.config (Application configuration) bin (directory for the executables to be delivered) obj (directory for the object files, working directory) Properties (AssemblyInfo.cs)

VS Project Directory z:\WP\Hello->Hello->bin (directory for the executables to be delivered) Release->Hello.exe (the non-debugable executable, smaller) Debug->Hello.exe (the debugable executable, larger) Debug->vshost.exe (VS hosting process for debugging) z:\WP\Hello->Hello->obj (directory for .obj and other temp files) Release->Hello.obj (the non-debugable obj, smaller) Debug->Hello.obj (the debugable obj, larger) Debug->TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92 (VS hosting process for debugging)

Create the same program using Notepad (1) Edit (create the source code using Notepad) Start->All Programs->Microsoft Visual Studio 20xx->Visual Studio Tools->Microsoft Visual Studio Command Prompt (20xx) Z: mkdir WP cd WP mkdir Hello2 cd Hello2 notepad Hello.cs & (background process) Copy code from the next page. (2) Compile (using the C-Sharp Compiler) csc /target:exe /out:Hello.exe Hello.cs (csc Hello.cs) (3)Excute Hello.exe

Create the same program using Notepad namespace Xiao { class MyApp static void Main () System.Console.WriteLine ("Hello, world"); System.Console.WriteLine ("Hit any key to end."); System.Console.Read(); // Don’t call “exit”. Why? } Day 1/21/2016

.NET Programming Examples http://www.cs.uakron.edu/%7Exiao/windows/Examples.zip Day 1/21/2016

Inside .NET Programs: FCL & CLR FCL (.NET framework class library): object-oriented API for writing managed applications more than 7,000 classes in named spaces: e.g. System.Windows.Forms, System.IO stored as DLLs (Dynamically Linked Libraries). http://msdn.microsoft.com/en-us/library/w0x726c2(v=vs.110).aspx CLR (common language runtime): execution engine for managed applications.

Source Code for Language 1 Source Code for Language 2 .NET Architecture for Language and Platform Independence (fan-in and fan-out on MSIL) Source Code for Language 1 Source Code for Language 2 Language 1 Compiler on OS1 Language 2 Compiler on OS2 MSIL Code Confirming CTS (Managed Code) CLR on OS1 CLR on OS2 Binary Code for OS1 Binary Code for OS2 OS1 OS2

Managed and Unmanaged Code Managed Code: application code whose every action is subject to approval by the CLR (common language runtime) and its compiler conforms to the CLS (common language specification) and supports the CTS (common type system). Unmanaged Code: native machine code that runs without CLR. Advantages of running managed code through CLR: Type safe (type checked by CLR at runtime) Light weight (multiple applications per process) Garbage collection

An Example Assembly Stoped 6/23/2017 teach .bat for PA1

Module/Metadata-Assembly/Manifest Contents of a managed module: CIL instructions generated from the source code Metadata describing code inside the module A CLR header containing important information about the module A Windows Portable Executable (PE) file header Metadata: a collection of tables that describe the code. TypeDef Class Names Assembly: is a collection of one or more files (modules) grouped together to form a logical unit. Manifest: metadata for an assembly. Name, version, data types exported. AL (Assembly Linker): joins files into assemblies.

Reflection Reflection: runtime understanding of the code (data types, program organizations, …) Reflection APIs: programming tools in System.Reflection namespace to read metadata. ILDASM: a program in .NET SDK to view the metadata using the reflection APIs DIA SDK: Debug Interface Access SDK The Microsoft Debug Interface Access Software Development Kit (DIA SDK) provides access to debug information stored in program database (.pdb) files (http://msdn.microsoft.com/library/en-us/diasdk/html/vsoriDebugInterfaceAccessSDK.asp) Stopped here 1/26/2016 day/eve

CIL CIL: Common Intermediate Language (e.g. MSIL) Other languages are merely syntactic devices for producing CIL. Microsoft provides CIL compilers for five languages: C#, J#, C++, Visual Basic, and JScript. Other companies provide: Perl, Python, Eiffel, and, even COBOL. Managed applications are Applications that target the .NET framework, written in one of the high-level languages, and translated into CIL code (managed code) by the compilers.

CIL cont. CIL compilers: translate code from other languages into CIL code. CIL is like a pseudo-assembly language that defines a native instruction set for the CLR (a virtual processor), there are about 100 instructions: ADD, BEQ (branch if equal), RET, BOX.…

The code translated into CIL ldc.i4.3 // Load a 32-bit (i4) 3 onto the stack stloc.0 // Store it in local variable 0 (a) ldc.i4.7 // Load a 32-bit (i4) 7 onto the stack stloc.1 // Store it in local variable 1 (b) ldloc.0 // Load local variable 0 onto the stack ldloc.1 // Load local variable 1 onto the stack add // Add the two and leave the sum on the stack stloc.2 // Store the sum in local variable 2 (c) int a = 3; int b = 7; int c = a + b; Each file is compiled into a managed module that can be run by CLR.

Using ILDASM In the VS Command Prompt window, cd z:\WP\Hello2, ildasm Hello.exe .method private hidebysig static void Main() cil managed { .entrypoint // Code size 30 (0x1e) .maxstack 8 IL_0000: nop IL_0001: ldstr "Hello, world" IL_0006: call void [mscorlib]System.Console::WriteLine(string) IL_000b: nop IL_000c: ldstr "Hit any key to end." IL_0011: call void [mscorlib]System.Console::WriteLine(string) IL_0016: nop IL_0017: call int32 [mscorlib]System.Console::Read() IL_001c: pop IL_001d: ret } // end of method MyApp::Main

Understanding CIL Examples in CS, V++ and VB at Examples\C1\Simple http://www.cs.uakron.edu/~xiao/windows/Examples.zip Check out the source code and the “executables.” Appreciate the statement: “Other languages are merely syntactic devices for producing CIL.”

Understanding CIL: CSCA.cs class Compute { public int Factorial(int f) int i; int result = 1; for (i=2; i <=f; i++) result = result * i; return result; }

Understanding CIL: CSCA.cs class ComputeFactorial { static void Main(string[] args) Compute c = new Compute(); int v = 5; System.Console.WriteLine("{0} factorial: {1}", v, c.Factorial(v)); System.Console.ReadLine(); }

Understanding CIL: CSCA.exe .method public hidebysig instance int32 . . .Factorial(int32 f) cil managed { // Code size 24 (0x18) .maxstack 2 .locals init (int32 V_0, int32 V_1, int32 V_2) IL_0000: ldc.i4.1 IL_0001: stloc.1 IL_0002: ldc.i4.2 IL_0003: stloc.0 IL_0004: br.s IL_000e IL_0006: ldloc.1 IL_0007: ldloc.0 IL_0008: mul IL_0009: stloc.1 IL_000a: ldloc.0 IL_000b: ldc.i4.1 IL_000c: add IL_000d: stloc.0 IL_000e: ldloc.0 IL_000f: ldarg.1 IL_0010: ble.s IL_0006 IL_0012: ldloc.1 IL_0013: stloc.2 IL_0014: br.s IL_0016 IL_0016: ldloc.2 IL_0017: ret } // end of method Compute::Factorial

Understanding CIL: CSCA.exe .method private hidebysig static void Main(string[] args) cil managed { .entrypoint // Code size 43 (0x2b) .maxstack 4 .locals init (class Compute V_0, int32 V_1) IL_0000: newobj instance void Compute::.ctor() IL_0005: stloc.0 IL_0006: ldc.i4.5 IL_0007: stloc.1 IL_0008: ldstr "{0} factorial: {1}" IL_000d: ldloc.1 IL_000e: box [mscorlib]System.Int32 IL_0013: ldloc.0 IL_0014: ldloc.1 IL_0015: callvirt instance int32 Compute::Factorial(int32) IL_001a: box [mscorlib]System.Int32 IL_001f: call void [mscorlib]System.Console::WriteLine(string, object, object) IL_0024: call string [mscorlib]System.Console::ReadLine() IL_0029: pop IL_002a: ret } // end of method ComputeFactorial::Main

Understanding CIL: VBCA.vb Module Module1 Class Compute Function Factorial(ByVal F As Integer) As Integer Dim I As Integer Dim Result As Integer = 1 For I = 2 To F Result = Result * I Next Return Result End Function End Class

Understanding CIL: VBCA.vb Sub Main() Dim C As Compute = New Compute() Dim V As Integer = 5 System.Console.WriteLine("{0} factorial: {1}", V, C.Factorial(V)) System.Console.ReadLine() End Sub End Module

Understanding CIL: VBCA.exe . .method public instance int32 Factorial(int32 F) cil managed { // Code size 28 (0x1c) .maxstack 2 .locals init (int32 V_0, int32 V_1, int32 V_2, int32 V_3) IL_0000: nop IL_0001: ldc.i4.1 IL_0002: stloc.2 IL_0003: ldc.i4.2 IL_0004: ldarg.1 IL_0005: stloc.3 IL_0006: stloc.1 IL_0007: br.s IL_0012 IL_0009: ldloc.2 IL_000a: ldloc.1 IL_000b: mul.ovf IL_000c: stloc.2 IL_000d: nop IL_000e: ldloc.1 IL_000f: ldc.i4.1 IL_0010: add.ovf IL_0011: stloc.1 IL_0012: ldloc.1 IL_0013: ldloc.3 IL_0014: ble.s IL_0009 IL_0016: ldloc.2 IL_0017: stloc.0 IL_0018: br.s IL_001a IL_001a: ldloc.0 IL_001b: ret } // end of method Compute::Factorial

Understanding CIL: VBCA.exe .method public static void Main() cil managed { .entrypoint .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) // Code size 46 (0x2e) .maxstack 4 .locals init (class VBCA.Module1/Compute V_0, int32 V_1) IL_0000: nop IL_0001: newobj instance void VBCA.Module1/Compute::.ctor() IL_0006: stloc.0 IL_0007: ldc.i4.5 IL_0008: stloc.1 IL_0009: ldstr "{0} factorial: {1}" IL_000e: ldloc.1 IL_000f: box [mscorlib]System.Int32 IL_0014: ldloc.0 IL_0015: ldloc.1 IL_0016: callvirt instance int32 VBCA.Module1/Compute::Factorial(int32) IL_001b: box [mscorlib]System.Int32 IL_0020: call void [mscorlib]System.Console::WriteLine(string, object, object) IL_0025: nop IL_0026: call string [mscorlib]System.Console::ReadLine() IL_002b: pop IL_002c: nop IL_002d: ret } // end of method Module1::Main

Three Components of CLR A just-in-time (JIT) compiler which converts CIL code into native binary machine code. A CTS: Common Type System which defines data types supported by .NET. A CLS: Common Language Specification which defines the language rules supported by .NET.

Chapter Summary .NET Framework is a platform for CLR applications (Windows, Web, anywhere CLR is supported) Applications that target the .NET Framework are managed applications. They’re (a) made of CIL and metadata, (b) JIT compiled at run time, and (c) executed by the CLR. Languages such as C# .NET are syntactic tools for generating CIL. (5) IDEs are all-in-one software development tools.