Web hosting services - CHAPTER 2 36 BUILDING C# APPLICATIONS Building

CHAPTER 2 36 BUILDING C# APPLICATIONS Building C# Applications Using csc.exe Now that your development machine recognizes csc.exe, the next goal is to build a simple single file assembly named TestApp.exe using the C# command-line compiler and Notepad. First, you need some source code. Open Notepad and enter the following: // A simple C# application. using System; class TestApp { public static void Main() { Console.WriteLine(”Testing! 1, 2, 3″); } } Once you have finished, save the file in a convenient location (e.g., C:CscExample) as TestApp.cs. Now, let s get to know the core options of the C# compiler. The first point of interest is to understand how to specify the name and type of assembly to create (e.g., a console application named MyShell.exe, a code library named MathLib.dll, aWindows Forms application named MyWinApp.exe, and so forth). Each possibility is represented by a specific flag passed into csc.exe as a command-line parameter (see Table 2-2). Table 2-2. Output-centric Options of the C# Compiler Option Meaning in Life /out This option is used to specify the name of the assembly to be created. By default, the assembly name is the same as the name of the initial input *.cs file (in the case of a *.dll) or the name of the type containing the program s Main() method (in the case of an *.exe). /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 (fully described in Chapter 11). /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. To compile TestApp.cs into a console application named TextApp.exe, change to the directory containing your source code file and enter the following command set (note that command-line flags must come before the name of the input files, not after): csc /target:exe TestApp.cs Here I did not explicitly specify an /out flag, therefore the executable will be named TestApp.exe, given that TestApp is the class defining the program s entry point (the Main() method). Also be aware that most of the C# compiler flags support an abbreviated version, such as /t rather than /target (you can view all abbreviations by entering csc /? at the command prompt): csc /t:exe TestApp.cs Furthermore, given that the /t:exe flag is the default output used by the C# compiler, you could also compile TestApp.cs simply by typing csc TestApp.cs
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Leave a Reply