The Role of Command Line Compiler (csc.exe)

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Utilizing the GDB debugger to analyze programs Background and application.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Creating a Console Application with Visual Studio
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Introduction to VB.NET Tonga Institute of Higher Education.
Microsoft Visual Basic 2005: Reloaded Second Edition
Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)
Creating a Project with C++ Builder
Introduction to the Visual Studio.NET IDE (LAB 1 )
Java and C# [this is a bonus – it is not a required lesson] ACO101: Introduction to Computer Science.
CPSC1301 Computer Science 1 Overview of Dr. Java.
Our Environment We will exercise on Microsoft Visual C++ v.6 We will exercise on Microsoft Visual C++ v.6 because that is what we have in the univ. because.
Active-HDL Interfaces Debugging C Code Course 10.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files.
Introduction to Exception Handling and Defensive Programming.
9/2/ CS171 -Math & Computer Science Department at Emory University.
Visual Basic.NET BASICS Lesson 1 A First Look at Microsoft Visual Basic.NET.
Microsoft Visual Basic 2005 BASICS Lesson 1 A First Look at Microsoft Visual Basic.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files 8/10/ :35 PM.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Building C# Applications
C# Programming: From Problem Analysis to Program Design
Dive Into® Visual Basic 2010 Express
Development Environment Setup
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Development Environment
Working with Data Blocks and Frames
Chapter 2: The Visual Studio .NET Development Environment
INF230 Basics in C# Programming
Getting Eclipse for C/C++ Development
ATS Application Programming: Java Programming
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Chapter Topics 15.1 Graphical User Interfaces
3.01 Apply Controls Associated With Visual Studio Form
Computer Programming I
1. Introduction to Visual Basic
3.01 Apply Controls Associated With Visual Studio Form
Using GUI Objects and the Visual Studio IDE
Important terms Black-box testing White-box testing Regression testing
Important terms Black-box testing White-box testing Regression testing
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Social Media And Global Computing Introduction to Visual Studio
Chapter 2 – Introduction to the Visual Studio .NET IDE
Advanced Programming Lecture 02: Introduction to C# Apps
Understanding the Visual IDE
1. Open Visual Studio 2008.
Microsoft Visual Studio
Getting Started: Developing Code with Cloud9
Digital Image Processing
Creating Your First C Program Using Visual Studio 2010
CSC235 - Visual Studio Tutorial
Tonga Institute of Higher Education
Our Environment We will exercise on Microsoft Visual C++ v.6
Creating Your First C Program Using Visual Studio 2010
CodePainter Revolution Trainer Course
Scripts In Matlab.
Getting Eclipse for C/C++ Development
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Workshop for Programming And Systems Management Teachers
Presentation transcript:

The Role of Command Line Compiler (csc.exe) Introduction C# is one of many possible languages which may be hosted by Visual Studio.NET Microsoft IDEs the professional and enterprise versions of VS.NET may be used to build various types of projects like C#, J#, VB.NET, MC++ and so on. In this unit will see how to set up environment variables to run C# applications using command line compiler The Role of Command Line Compiler (csc.exe) One way is to use the C# command-line compiler, csc.exe (where csc stands for C-Sharp Compiler) We discuss the installation .NET Framework 2.0 SDK, Since we don’t build a large scale application using a command line compiler it is important to understand the basics of how to compile *.cs files by hand. When you use graphical IDEs to build applications, you are ultimately instructing csc.exe how to manipulate your C# input files.

Configuring the C# Command-Line Compiler 1. Right-click the My Computer icon and select Properties from the pop-up menu. 2. Select the Advanced tab and click the Environment Variables button. 3. Double-click the Path variable from the System Variables list box. 4. Add the following line to the end of the current Path value: C:\Windows\Microsoft.NET\Framework\v2.0.50215 To check whether the setting has been done properly or not, open a command prompt and type csc -? Or csc /? Configuring Additional .NET Command-Line Tools We have to set Path variable with one more line as C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin This directory contains additional command-line tools that are commonly used during .NET development.

Configuring Additional .NET Command-Line Tools We have to set Path variable with one more line as C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin This directory contains additional command-line tools that are commonly used during .NET development. To confirm this new setting, enter the following command in a command prompt to view the options of the GAC (global assembly cashe) utility, gacutil.exe: gacutil -? Note that the above explained method is to compile the C# program in any command prompt. Instead of that, we can directly use the SDK in the Visual Studio Tools menu.

// A simple C# application. using System; class Test { Building C# Applications Using csc.exe To build a simple C# application, open a notepad and type the following code:   // A simple C# application. using System; class Test { public static void Main() Console.WriteLine("Hello World!!!"); } Save this file in any convenient location as Test.cs.

Output-centric Options of the C# Compiler File Output Option Meaning /target:exe This option builds an executable console application. This is the default file output type, and thus may be omitted when building this application type. /target:library This option builds a single-file *.dll assembly. /target:module This option builds a module.Modules are elements of multifile assemblies. /target:winexe Although you are free to build Windows-based applications using the /target:exe flag, the /target:winexe flag prevents a console window from appearing in the background.

Referencing External Assemblies Note that mscorlib.dll is automatically referenced during the compilation process. using System; using System.Windows.Forms;   class Test { public static void Main() MessageBox.Show("Hello..."); } Since we have made use of the MessageBox class, we must specify the System.Windows.Forms.dll assembly using the /reference flag which can be abbreviated to /r as – csc /r:System.Windows.Forms.dll Test.cs

Now, running the application will give the output as –

public static void Main() MyTest t = new MyTest (); t.display(); } Compiling Multiple Source Files with csc.exe When we have more than one *.cs source file, then we can compile them together. Example: File Name: MyTest.cs using System; using System.Windows.Forms; class MyTest { public void display() MessageBox.Show("Hello..."); } File Name: Test.cs   using System; class Test { public static void Main() MyTest t = new MyTest (); t.display(); } We can compile C# files by listing each input file explicitly: csc /r:System.Windows.Forms.dll Test.cs MyTest.cs csc /r:System.Windows.Forms.dll; System.Drawing.dll *.cs (For Referencing Multiple External Assemblies)

FEW TOPICS TO BE WRITTEN

Remaining C# Compiler Options C# compiler has many flags that can be used to control how the .NET assembly to be generated. Following table lists some of the flags and their meaning. /lib Specifies the location of assemblies referenced via /reference /linkresource Used to create a link to a managed resource /main Specifies which Main() method to use as the program’s entry point if multiple Main() methods have been defined in the current *.cs file set. /out Specifies the name of the output file /warn Used to sent warning level for the compilation cycle /warnaserror Used to automatically promote warnings to errors /reference Used to reference an external assembly /resource Used to embed .NET resources into the resulting assembly

.NET Framework SDK provides a command-line debugger named cordbg.exe. The Command-Line Debugger (cordbg.exe) .NET Framework SDK provides a command-line debugger named cordbg.exe. You may view them by specifying the /? flag: cordbg /? Command Line Flag of cordbg.exe Meaning b[reak] Set or display current breakpoints. [ete] Remove one or more breakpoints. ex[it] Exit the debugger g[o] Continue debugging the current process until hitting next breakpoint. o[ut] Step out of the current function. p[rint] Print all loaded variables (local, arguments, etc.). si Step into the next line. so Step over the next line.

Debugging at the Command Line The first step is to generate debugging symbols for your current application by specifying the /debug flag of csc.exe. csc @testapp.rsp /debug This generates a new file named testapp.pdb. If you do not have an associated *.pdb file, it is still possible to make use of cordbg.exe; however, you will not be able to view your C# source code during the process

C# Preprocessor Symbol C# Preprocessor Directives C# Preprocessor Symbol Meaning #define, #undef Used to define and un-define conditional compilation symbol. #if, #elif, #else, #endif Used to conditionally skip sections of source code. #line Used to control the line numbers emitted for errors and warnings #error, #warning Used to issue errors and warnings for the current build #region, #endregion Used to explicitly mark sections of source code. Under VS.NET, regions may be expanded and collapsed within the code window. Other IDEs (including text editors) will ignore these symbols.

Specifying Code Regions Using #region and #endregion tags, we can specify a block of code that may be hidden from view and identified by a textual marker. class Test { ……. #region Unwanted public class sub1 } public interface sub2 ………… #endregion

Conditional Code Compilation: #define MAX using System;   class Test { public static void Main() #if(MAX) Console.WriteLine("MAX is defined"); #else Console.WriteLine("MAX is not defined"); #endif } The output will be: MAX is defined