The Microsoft® Shared Source implementation of the C# compiler is very similar to the implementation in Microsoft® .NET Framework SDK and Microsoft® Visual Studio® .NET. Both implementations originate from the same source base but some options and features that rely on functionality in Microsoft Windows have been removed from the Shared Source implementation.
The following option areas and related options were modified
Complete documentation for the .NET Framework C# compiler and tutorials are available on msdn.microsoft.com. Other than the changes mentioned above, the functionality in the Shared Source implementation of the C# compiler is the same as the .NET Framework implementation.
Note: Because the C# compiler builds complete portable executable (PE) files (.exes, .dlls, netmodules) it can be considered a compiler and linker. The compiler has linker-style options that set Windows-specific information in the generated PE file. The Shared Source implementation of the CLI loads applications using the clix loader and does not use the Window system loader at all. This means that Windows-specific PE settings are ignored even when Shared Source is running on Windows. However, if the generated assembly is executed under the .NET Framework the file will be loaded by the system loader and the information in the PE file will be used. Some of the options in this category are:
The compiler produces PE format executable (.exe) files, dynamic-link libraries (.dll), or code modules (.netmodule). For information on the PE format of files loaded by ECMA CLI implementations see the ECMA-335 Common Language Infrastructure specification, Partition II, section 24.
For information on how the Shared Source CLI (SSCLI) implementation loads PE files, see the implemention code for the clix application loader: sscli\clr\src\tools\clix. Also see sscli\clr\src\vm\cormap.cpp for the PE loader implementation.
The C# compiler can be invoked at the command line by typing the name of its executable file (csc.exe on Windows and just csc on FreeBSD) on the command line. See env.html for more details on correctly setting your environment to build and execute SSCLI utilities including the C# compiler.
The C# compiler code uses the following rules when interpreting arguments given on the operating system command line:
Every compiler option is available in two forms: -option and /option.
[FreeBSD note: To avoid ambiguity between filenames and '/' on FreeBSD and the /option form, use the -option form.]
| Option | Purpose | |
|---|---|---|
@response_file |
Specify a response file, response_file. The @
option lets you specify a file that contains compiler options and source code
files to compile. These compiler options and source code files will be processed
by the compiler just as if they had been specified on the command line.
|
|
/? |
Output compiler options to the console. Same as
/help This option sends a listing of compiler options, and a brief description of each option, to stdout. If this option is included in a compilation, no output file will be created and no compilation will take place. |
|
/addmodule:file[;file2] |
Specify one or more modules (file, file2, and
so on) to be part of this assembly.
All modules added with /addmodule must be in the same directory as the output
file at run time. That is, you can specify a module in any directory at compile
time but the module must be in the application directory at run time. If the
module is not in the application directory at run time, you will get a
System.TypeLoadException. |
|
/baseaddress:address_value |
Specify the preferred base address (address_value) at which to load a DLL.
The loading base address is only relevant if the file is going to be run on the Microsoft .NET Framework on Windows. Differences in loading behavior can occur in the .NET Framework on Windows depending on the version of the Windows operating system. The SSCLI implementation ignores base address information stored in the PE assembly file. For details on how the SSCLI implementation loads PE files see sscli\clr\src\vm\cormap.cpp. For information on the PE format of files loaded by ECMA CLI implementations see the ECMA-335 Common Language Infrastructure specification, Partition II, section 24. For more information on DLL base addresses in Windows, go to msdn.microsoft.com and search for "dll base address". The Microsoft Windows Platform SDK tool Rebase.exe documentation and the Microsoft Visual Studio Linker.exe documentation provide detailed information. |
|
/checked[+ | -] |
Specify whether integer arithmetic that overflows the bounds of the data type will cause an exception at run time.
The /checked option specifies whether an integer arithmetic statement that is
not in the scope of the checked or unchecked keywords and that results in a
value outside the range of the data type shall cause a run-time exception. |
|
/codepage:id |
Specify the code page to use for all source code files
in the compilation with id. If you compile one or more source code
files that were not created to use the default code page on your computer, you
can use the -codepage option to specify which code page should be used. |
|
/debug[+ | -] |
Emit debugging information. The /debug option causes the compiler to generate debugging information and place it in the output file(s). Use this option to create debug builds. If /debug, /debug+, or /debug:full is not specified, you will not be able to debug the output assembly at the source code level. Options values:
Specifying +, or just /debug, causes the compiler to generate debugging information and place it in a program database (.ildb file). Specifying -, which is in effect if you do not specify /debug, causes no debug information to be created.
Specifies the type of debugging information generated by the compiler. The full argument, which is in effect if you do not specify /debug:pdbonly, enables attaching a debugger to the running program. Specifying pdbonly allows source code debugging when the program is started in the debugger but will display CIL only when the running program is attached to the debugger. |
|
/define:name[;name2] |
Define preprocessor symbols where name, name2
are the names of one or more symbols that you want to define. The /define option defines name as a symbol in your program. It has the
same effect as using a #define preprocessor directive in your source file. A
symbol remains defined until an #undef directive in the source file removes the
definition or the compiler reaches the end of the file.
You can define multiple symbols with /define by using a semicolon or comma to separate symbol names. For example:
|
|
/filealign:number |
Specify the size of sections in the output file where
number is a value that specifies the size of sections in the output file.
Valid values are 512, 1024, 2048, 4096, 8192, and 16384. These values are in
bytes.
The information stored in the PE file as the result of using this option is not used on the SSCLI implementation of the CLI assembly loader. It would only be meaningful if the file is going to be loaded in the Microsoft .NET Framework on Windows. |
|
/fullpaths |
Specify the absolute path to the file in compiler output. By default, errors and warnings that result from compilation specify the name of the file in which an error was found. The /fullpaths option causes the compiler to specify the full path to the file. |
|
/help |
Output compiler options to the console. Same as
/? This option sends a list of compiler options, and a brief description of each option, to stdout. If this option is included in a compilation, no output file will be created and no compilation will take place. |
|
/incremental[+ | -] |
Enable incremental compilation of source code files. The /incremental compiler option enables the incremental compiler, which compiles only those methods that have changed since the last compilation. Information about the state of the previous compilation is stored in the following files, which are created by the compiler:
When compiling with /debug, the status of debug information is stored in the program database (.pdb file).
Information about the status of the compilation, other than debug
information, is stored in a .incr file. |
|
/lib:dir1[, dir2] |
Specify the location of assemblies referenced via /reference
where dir1 is a directory for the compiler to look in if a referenced
assembly is not found in the current working directory (the directory from which
you are invoking the compiler) or in the CLI implementation assembly directory
and dir2 is one or more additional directories to search in for assembly
references.
Separate additional directory names with a comma. The /lib option specifies the location of assemblies referenced via the
/reference option.
Use /reference to specify an assembly reference. |
|
/linkresource:filename[,identifier] |
Create a link to a managed resource where filename
is the resource file to which you want to link from the assembly and
identifier (optional) is the logical name for the resource (the name used in
code to load the resource). The default identifier is the name of the file name. The /linkresource option creates a link to a resource in the output
file; the resource file is not placed in the output file. The /resource option
embeds a resource file in the output file. |
|
/main:class |
Specify the location of the Main method where class
is the type that contains the Main method. If your compilation includes more than one type with a Main method, the /main option allows you to specify which type contains the Main method that you want to use as the entry point into the program. This option is only for use when compiling an .exe file. |
|
/nologo |
Suppress compiler banner information. The /nologo option suppresses the display of the sign-on banner when the compiler starts up and display of informational messages during compiling. |
|
/nostdlib[+ | -] |
Do not import the base class library (mscorlib.dll). The /nostdlib option prevents the import of mscorlib.dll, which defines the entire System namespace. Use this option if you want to define or create your own System namespace and objects. This option is used by the SSCLI build system in order to bootstrap the build
of the base class libraries in mscorlib.dll. |
|
/noconfig |
Do not compile with the global or local versions of csc.rsp.
The /noconfig option tells the compiler not to compile with the global or local
versions of csc.rsp. |
|
/nowarn:number1[,number2[...]] |
Suppress the compiler's ability to generate
specified warnings where number1, number2 are warning numbers that you
want the compiler to suppress. The /nowarn option lets you suppress the
compiler's ability to generate one or more warnings. Separate multiple warning
numbers with a comma. |
|
/optimize[+ | -] |
Enable/disable optimizations. The /optimize option
enables or disables optimizations performed by the compiler to make your output
file smaller, faster, and more efficient. /optimize also tells the common
language runtime to optimize code at runtime. |
|
/out:filename |
Specify output file where filename is the
name of the output file created by the compiler.
The /out option specifies the name of the output file. The compiler expects
to find one or more source code files following the /out option.
On the command line, it is possible to specify multiple output files for your
compilation. All source code files specified after an /out option will be
compiled into the output file specified by that /out option. A source code file
used to compile one output file cannot be used in the same compilation for the
compilation of another output file. |
|
/recurse:[dir\]file |
Search subdirectories for source files to compile
where dir (optional) is the directory in which you want the search to
begin and file is the file(s) to search for. Wildcard characters are
allowed.
If dir not specified, the search begins in the directory where the csc command was executed. The /recurse option lets you compile source code files in all child
directories of either the specified directory (dir) or the directory where the
csc command was executed. |
|
/reference:file[;file2] |
Imports the information in the metadata of the
referenced assembly for use in resolving external references where file,
file2 are one or more files that contains an assembly manifest. To import
more than one file, separate file names with either a comma or a semicolon.
The /reference option causes the compiler to make public type information in
the specified files available to the project you are currently compiling.
Use /lib to specify the directory in which one or more of your assembly
references is located. The /lib topic also discusses which directories the
compiler searches for assemblies. |
|
/resource:filename[,identifier] |
Embed a .NET Framework resource into the output file
where filename is the SSCLI resource file you want to embed in the output
file and identifier (optional) is the logical name for the resource; the
name used in code to load the resource.
The default identifier is the name of the file name. Use /linkresource to link a resource to an assembly and not place the
resource file in the output file. |
|
/target:output_type |
Specifies the type of assembly to be generated by
the compiler. Unless you specify /target:module, /target causes assembly
metadata to be placed in an output file.
The compiler creates only one assembly manifest per compilation. Information
about all files in a compilation is placed in the assembly metadata. All output
files except those created with /target:module can contain an assembly manifest.
When producing multiple output files at the command line, only one assembly
manifest can be created and it must go into the first output file specified on
the command line. If the first output file is an executable assembly
(/target:exe or /target:winexe) or code library (/target:library), then any
other output files produced in the same compilation must be modules
(/target:module). Specify the format of the output file using one of four options: |
|
/target:exe |
The /target:exe option causes the compiler to create an executable
(EXE), console application. The /target:exe option is in effect by default. The
executable file will be created with the .exe extension. Unless otherwise specified with the /out option, the output file name takes the name of the input file that contains the Main method. When specified at the command line, all files up to the next /out, /target:winexe, or /target:library option are used to create the .exe file. The /target:exe option is in effect for all files since the previous /out or /target:library option. One and only one Main method is required in the source code files that are compiled into an .exe file. The /main compiler option lets you specify which class contains the Main method, in cases where your code has more than one class with a Main method. |
|
/target:library |
The /target:library option causes the compiler to create a
dynamic-link library (DLL) rather than an executable file (EXE). The DLL will be
created with the .DLL extension. Unless otherwise specified with the /out option, the output file name takes the name of the first input file. When specified at the command line, all files up to the next /out, /target:winexe, or /target:exe option are used to create the .dll file. When building a .DLL file, a Main method is not required. |
|
/target:module |
To not generate an assembly manifest, use the /target:module
option. By default, the output file will have an extension of .netmodule. A file that does not have an assembly manifest cannot be directly loaded by the SSCLI execution engine. However, such a file can be incorporated into the assembly manifest of an assembly via /addmodule. If more than one module is created in a single compilation, internal types in one module will be available to other modules in the compilation. When code in one module references internal types in another module, then both modules must be incorporated into an assembly manifest, via /addmodule. |
|
/target:winexe |
The /target:winexe option causes the compiler to create an
executable (EXE) Windows GUI application. The executable file will be created
with the .exe extension. This sets the subsystem information in the PE file
which is used by Microsoft Windows to determine some execution characteristics
of the application. This information is ignored by the SSCLI implementation of
the CLI. However, if the application is executed under the Microsoft .NET
Framework this option will have an impact. For more information on the
console or Windows subsystem setting see http:msdn.microsoft.com and search for
"console subsystem". |
|
/unsafe |
The /unsafe option allows code that uses the unsafe keyword to compile. | |
/utf8output |
Display compiler output using UTF-8 encoding. The
/utf8output option displays compiler output using UTF-8 encoding. |
|
/warn:option |
The /warn option specifies the warning level for the
compiler to display. The Build Errors documentation describes the warnings, indicates each warning's level, and indicates potential problems (rather than actual coding errors) with statements that may not compile as you intend. Use /warnaserror to treat all warnings as errors. /w is the short form of /warn. option is the minimum warning level you want displayed for the build. Valid values are 0-4: |
|
| Warning Level | Meaning | |
| 0 | Turns off emission of all warning messages. | |
| 1 | Displays severe warning messages. | |
| 2 | Displays level 1 warnings plus certain, less-severe warnings, such as warnings about hiding class members. | |
| 3 | Displays level 2 warnings plus certain, less-severe warnings, such as warnings about expressions that always evaluate to true or false. | |
| 4 | Displays all level 3 warnings plus informational warnings. This is the default warning level at the command line. | |
/warnaserror[+ | -] |
Promote warnings to errors. The /warnaserror+
option treats all warnings as errors. Any messages that would ordinarily be
reported as warnings are instead reported as errors, and the build process is
halted (no output files are built). |
|
csc File.cs
csc /target:library File.cs
csc /out:My.exe File.cs
csc /define:DEBUG /optimize /out:File2.exe *.cs
csc /target:library /out:File2.dll /warn:0 /nologo /debug *.cs
csc /target:library /out:Something.xyz *.cs
Copyright (c) 2002 Microsoft Corporation