You are on page 1of 20

Chapter 2

Building C# Applications

Objectives
Command Line Compilation

Visual Studio .NET IDE


Referencing External Assemblies

Demo Multi Language

Configuration for csc


Right Click My Computer Properties Advanced Environment variables Double Click Path

Add the path where csc.exe is loaded C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322


3

Command Line Compilation


Compiling single source file csc /target:exe TestApp.cs or csc TestApp.cs csc C Sharp Compiler /target:exe *.exe console application /target:winexe windows application /out to name the output File Compiling multiple source files
csc /r:System.Windows.Forms.dll TestApp.cs Hello.cs
4

Example (Console based)


// Hello.cs using System; public class Hello { public static void Main(String[ ] args) { Console.WriteLine("Hello World"); } }
5

Example (Windows based)


// HelloWin.cs using System; using System.Windows.Forms; public class HelloWin { public static void Main(String[ ] args) { Console.WriteLine("Hello World"); MessageBox.Show("Hi, I am now in Windows!"); } }
6

Compiling Multiple Source Files


// Car.cs using System; public class Car { public void Display() { MessageBox.Show ("Car Class"); } } // HelloDriver.cs using System; public class HelloDriver { public static void Main (String[ ] args) { Console.WriteLine ("Hello World"); Car c = new Car(); c.Display(); } }
HelloDriver.cs Car.cs 7

csc

/r:System.Windows.Forms.dll

CSC.exe Response Files


Building a complex application is burden C# response files contain all the instructions to be used during the compilation of current build
( /r:System.Windows.Forms.dll /target.exe /out:TestApp.exe)

Entire apllication build using @ symbol (csc @ TestApp.rsp) End with *.rsp (response) extension
8

CSC.exe Response Files


These are used as an alternative to pounding out lines & lines of flags manually at the command prompt csc.rsp is the default response file To disable automatic reading of csc.rsp, specify /noconfig flag csc @ TestApp.rsr /noconfig

Generating Bug Reports


C# provides flag /bugreport It include any errors encountered during the compilation process of current build csc /bugreport:bugs.txt TestApp.cs Open bug report in *.txt file (i.e. bugs.txt)

10

Command Line Debugger (cordbg.exe)


.NET SDK provide command line debugger cordbg.exe It provides several flags, to view flags cordbg-?
b[reak] del[ete] ex[it] g[o] set or display current break points Remove one or more break points exit debugger continue debugging etc.

Generate debugging by specifying - /debug flag csc @ TestApp.rsp /debug It generates new file TestApp.pdb Open a session with cordbg.exe 11 c:\>cordbg.exe TestApp.exe

Program to illustrate command line arguments


using System; class CommandLine { static void Main(string[ ] args) { double argvalue=0.0; double sqrtvalue=0.0; if(args.Length==0) { Console.WriteLine(No arguments); Console.ReadLine(); } return; Argvalue=double.Parse(args[0].ToString()); Sqrtvalue=Math.Sqrt(argvalue); Console.WriteLine(Square root of the argument is : {0}\n, sqrtvalue); } }

12

Visual Studio .NET IDE


.NET Start Page

13

.NET Project Window

14

Project Types
Windows Application Class Library Windows Control Library Windows Forms Builds single file assembly (*.dll) Same as ActiveX Control

ASP .NET Web Application Builds ASP .NET Web Application ASP .NET Web Service Web Control Library .NET Web Service Customized Web Controls

Console Application
Windows Services

Old Console based


NT/2000 services
(background worker applications)
15

.NET Main Page


Tool Box

Solution Explorer View

Class View

16

Configuring a C# Project

17

Referencing External Assemblies


These are predefined list of assemblies automatically recognized by .NET

18

Other features of .NET IDE


Debugging Breakpoints XML Related Editing Tools Object Browser Help Menu (F1 is your friend) Documenting the Source Code (XML) C# Preprocessor Directives

19

Web Sites for Other IDEs


www.gotdotnet.com www.icsharpcode.net

20

You might also like