Appendix B: C Compilation Options

 
Appendix B - C# Compilation Options
bySimon Robinsonet al.
Wrox Press 2002
  

This appendix lists the various C# compiler options that you may use if you have to compile your C# projects without the benefit of Visual Studio .NET, or if you want to carry out compiler operations not supported by Visual Studio .NET. They have been arranged as a series of tables according to category. First, however, we will give a brief overview of how to use the C# compiler.

Using the C# Compiler

Freely distributed with the .NET Framework SDK, the C# compiler, csc.exe , can be invoked from a DOS command line or from the VS.NET IDE that most readers will probably end up using. In order to use the C# compiler you need to set up certain environment variables . Let's look at the steps to do this now.

Open up the System Properties window, Start Settings Control Panel System , and switch to the Advanced tab:

click to expand

Now click on the Environment Variables button. In the System variables window double-click on the Path variable so that we can edit it, and add in the path to the version of the Framework that you have installed on your computer (on my computer this is C:\WINNT\Microsoft.NET\Framework\v1.0.3705 ):

click to expand

Note that you will need to use a semicolon to separate this path variable from those that are already in there.

The compiler's behavior is controlled by command-line arguments. When you tell an IDE like VS.NET to compile a C# program, the IDE consults its settings to dynamically build the command string with the command-line arguments and uses this string to shell out to a csc.exe process. Although using an IDE like VS.NET certainly saves you a lot of time and keystrokes, it's good to know the command-line options for controlling the C# compiler in case you want to automate your organization's build process through scripts, batch files, and so on.

Input and Output Files

When invoking the C# compiler from the command line, you indicate your source file simply by listing its filename after the name of the compiler, csc . You indicate the name for the target file by using the output argument:

  csc SourceFile.cs /out:TargetFile.exe  

Compiling Different Project Types

C# can be used to create different kinds of projects, such as console applications, Windows Form applications, components , and more. You use the /target command-line option to tell the C# compiler what kind of project it needs to build:

  • The /target:exe argument tells the C# compiler to produce a console application.

  • The /target:winexe argument tells the C# compiler to produce a Windows Form application.

  • The /target:library argument tells the C# compiler to produce a standalone assembly containing a manifest.

  • The /target:module arguments also tells the C# compiler to produce an assembly file, but without a manifest. Manifest-less assemblies produced with the /target:module argument can be subsumed into other assembly components that do contain manifests .

Response Files

To make automating builds easier, the C# compiler supports response files . A response file contains a listing of command-line options and can be linked in by a reference to the file when the compiler is invoked. You denote a response file on the command line by prefixing it with the " @ " symbol:

  csc /out:TargetFile.exe  @<responsefilename> SourceFile.cs  
  


Professional C#. 2nd Edition
Performance Consulting: A Practical Guide for HR and Learning Professionals
ISBN: 1576754359
EAN: 2147483647
Year: 2002
Pages: 244

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net