Subscribe

RSS Feed (xml)

Using csc.exe, the C# Command-Line Compiler

Although the Visual Studio IDE is what you will probably be using for your commercial projects, the C# command-line compiler is the easiest way to compile and run most of the sample programs shown in this book. To create and run programs using the C# commandline compiler, you will follow these three steps:


Enter the program using a text editor.
Compile the program.
Run the program.
Entering the Program

The programs shown in this book are available from Osborne’s web site: www.osborne.com. However, if you want to enter the programs by hand, you are free to do so. In this case, you must enter the program into your computer using a text editor, such as Notepad. Remember, you must create text-only files, not formatted word-processing files, because the format information in a word processor file will confuse the C# compiler. When entering the program, call the file Example.cs.
Compiling the Program

To compile the program, execute the C# compiler, csc.exe, specifying the name of the source file on the command line, as shown here:
C:\>csc Example.cs

The csc compiler creates a file called Example.exe that contains the MSIL version of the program. Although MSIL is not executable code, it is still contained in an exe file. The Common Language Runtime automatically invokes the JIT compiler when you attempt to execute Example.exe. Be aware, however, that if you try to execute Example.exe (or any other exe file that contains MSIL) on a computer for which the .NET Framework is not installed, the program will not execute because the CLR will be missing.
Note Prior to running csc.exe, you may need to run the batch file vcvars32.bat, which is typically found in the \Program Files\Microsoft Visual Studio 8\VC\Bin directory. Alternatively, you can activate a command-prompt session that is already initialized for C# by selecting a Visual Studio 2005 Command Prompt from the list of tools shown under the Microsoft Visual Studio 2005 entry in the Start
Programs menu of the task bar. Alternatively, you can select SDK Command Prompt shown under the Microsoft .NET Framework SDK 2.0 entry in the Start
Programs menu of the task bar.


Running the Program

To actually run the program, just type its name on the command line, as shown here:


C:\>Example

When the program is run, the following output is displayed:
A simple C# program.

1 comment:

  1. Wondering where to go in 2021? Things to do has ranked as the best include a remote, idyllic island, the design capital .

    ReplyDelete

LocalsAdda.com-Variety In Web World

Fun Mail - Fun in the Mail