CHAPTER 2 BUILDING C# APPLICATIONS
Option
Meaning in Life
/target:winexe
Although you are free to build graphical user interface–based applications
using the /target:exe option, /target:winexe prevents a console window
from appearing in the background.
Note The options sent to the command-line compiler (as well as most other command-line tools) can be
prefixed with either a dash (-) or a slash (/).
To compile TestApp.cs into a console application named TestApp.exe, change to the directory
containing your source code file using the cd (“change directory”) command:
cd C:\CscExample
Then, 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 name of the input file. 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 the following:
csc TestApp.cs
TestApp.exe can now be run from the command line by typing the name of the executable, as shown
in Figure 2-2.
Figure 2-2. Compiling and running TestApp.exe
42