Sunteți pe pagina 1din 20

Chapter 2

Building C# Applications

1
Objectives
Command Line Compilation
Visual Studio .NET IDE
Referencing External Assemblies
Demo Multi Language

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

csc /r:System.Windows.Forms.dll HelloDriver.cs Car.cs 7


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

9
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] set or display current break points
del[ete] Remove one or more break points
ex[it] exit debugger
g[o] 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
c:\>cordbg.exe TestApp.exe
11
Program to illustrate command
line arguments
using System; Argvalue=double.Parse(args[0].ToString());
class CommandLine
{ Sqrtvalue=Math.Sqrt(argvalue);
static void Main(string[ ] args)
Console.WriteLine(Square root of the
{
argument is : {0}\n, sqrtvalue);
double argvalue=0.0;
}
double sqrtvalue=0.0; }
if(args.Length==0)
{
Console.WriteLine(No arguments);
Console.ReadLine();
} return;

12
Visual Studio .NET IDE
.NET Start Page

13
.NET Project Window

14
Project Types
Windows Application Windows Forms
Class Library Builds single file assembly
(*.dll)
Windows Control Library Same as ActiveX Control
ASP .NET Web Application Builds ASP .NET Web
Application
ASP .NET Web Service .NET Web Service
Web Control Library Customized Web Controls
Console Application Old Console based
Windows Services NT/2000 services
(background worker applications)
15
.NET Main Page Solution
Tool Explorer
Box 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

S-ar putea să vă placă și