CHAPTER 2 BUILDING C# APPLICATIONS
The Developer Command Prompt
When you install the .NET Framework 4.5 SDK, Visual Studio, or Visual C# Express, you will end up with
a number of new directories on your local hard drive, each of which contains various .NET development
tools. Many of these tools are driven from the command prompt, so if you wish to use these utilities from
any Windows command window, you will need to register these paths with the operating system.
While you could update your machine’s PATH variable manually to do so, you can save yourself some
time by simply making use of the Developer Command Prompt (see Figure 2-1) that is accessible from
the Start All Programs Microsoft Visual Studio 11 Visual Studio Tools folder.
Figure 2-1. The Developer Command Prompt
The benefit of using this particular command prompt is that it has been preconfigured to provide
access to each of the .NET development tools. Assuming you have a .NET development environment
installed, type the following command and press the Enter key:
csc -?
If all is well, you should see a list of command-line arguments of the C# command-line compiler
(where csc stands for the C-sharp compiler). As you can see, this command-line compiler has a bevy of
options; however, in practice you will only need to make use of a handful of settings to build C#
programs at the command prompt.
Building C# Applications Using csc.exe
While it is true that you might never decide to build a large-scale application using nothing but the C#
command-line compiler, it is important to understand the basics of how to compile your code files by
hand. I can think of a few reasons you should get a grip on the process.
40
•
The most obvious reason is the simple fact that you might not have a copy of
Visual Studio or another graphical IDE.
•
You might be in a college or university setting where you are prohibited from
using code-generation tools/IDEs in the classroom.
•
You plan to make use of automated build tools, such as msbuild.exe, which
require you to know the command-line options of the tools you are utilizing.
•
You want to deepen your understanding of C#. When you use graphical IDEs to
build applications, you are ultimately instructing csc.exe how to manipulate your
C# input files. In this light, it’s edifying to see what takes place behind the scenes.